通讯录或者事件列表需要用到此功能,先看截图
下载地址:IndexableListView-master
package com.woozzu.android.indexablelistview; import java.util.ArrayList; import java.util.Collections; import java.util.List; import android.app.Activity; import android.content.Context; import android.os.Bundle; import android.widget.ArrayAdapter; import android.widget.SectionIndexer; import com.woozzu.android.util.StringMatcher; import com.woozzu.android.widget.IndexableListView; public class IndexableListViewActivity extends Activity { private ArrayListmItems; private IndexableListView mListView; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); mItems = new ArrayList (); mItems.add("Diary of a Wimpy Kid 6: Cabin Fever"); mItems.add("Steve Jobs"); mItems.add("Inheritance (The Inheritance Cycle)"); mItems.add("11/22/63: A Novel"); mItems.add("The Hunger Games"); mItems.add("The LEGO Ideas Book"); mItems.add("Explosive Eighteen: A Stephanie Plum Novel"); mItems.add("Catching Fire (The Second Book of the Hunger Games)"); mItems.add("Elder Scrolls V: Skyrim: Prima Official Game Guide"); mItems.add("Death Comes to Pemberley"); mItems.add("Diary of a Wimpy Kid 6: Cabin Fever"); mItems.add("Steve Jobs"); mItems.add("Inheritance (The Inheritance Cycle)"); mItems.add("11/22/63: A Novel"); mItems.add("The Hunger Games"); mItems.add("The LEGO Ideas Book"); mItems.add("Explosive Eighteen: A Stephanie Plum Novel"); mItems.add("Catching Fire (The Second Book of the Hunger Games)"); mItems.add("Elder Scrolls V: Skyrim: Prima Official Game Guide"); mItems.add("Death Comes to Pemberley"); mItems.add("Zeath Comes to Pemberley"); mItems.add("Xeath Comes to Pemberley"); Collections.sort(mItems); ContentAdapter adapter = new ContentAdapter(this, android.R.layout.simple_list_item_1, mItems); mListView = (IndexableListView) findViewById(R.id.listview); mListView.setAdapter(adapter); mListView.setFastScrollEnabled(true); } private class ContentAdapter extends ArrayAdapter implements SectionIndexer { private String mSections = "#ABCDEFGHIJKLMNOPQRSTUVWXYZ"; public ContentAdapter(Context context, int textViewResourceId, List objects) { super(context, textViewResourceId, objects); } @Override public int getPositionForSection(int section) { // If there is no item for current section, previous section will be selected for (int i = section; i >= 0; i--) { for (int j = 0; j < getCount(); j++) { if (i == 0) { // For numeric section for (int k = 0; k <= 9; k++) { if (StringMatcher.match(String.valueOf(getItem(j).charAt(0)), String.valueOf(k))) return j; } } else { if (StringMatcher.match(String.valueOf(getItem(j).charAt(0)), String.valueOf(mSections.charAt(i)))) return j; } } } return 0; } @Override public int getSectionForPosition(int position) { return 0; } @Override public Object[] getSections() { String[] sections = new String[mSections.length()]; for (int i = 0; i < mSections.length(); i++) sections[i] = String.valueOf(mSections.charAt(i)); return sections; } } }
下载地址:IndexableListView-master
收藏的用户(0) X
正在加载信息~
推荐阅读
最新回复 (0)
站点信息
- 文章2300
- 用户1336
- 访客10859735
每日一句
True success inspires others to act.
真正的成功是激励他人行动。
真正的成功是激励他人行动。
语法错误: 意外的令牌“标识符”
全面理解Gradle - 定义Task
Motrix全能下载工具 (支持 BT / 磁力链 / 百度网盘)
谷歌Pixel正在开始起飞?
获取ElementUI Table排序后的数据
Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is
亲测!虚拟机VirtualBox安装MAC OS 10.12图文教程
华为手机app闪退重启界面清空log日志问题
android ndk开发之asm/page.h: not found
手机屏幕碎了怎么备份操作?
免ROOT实现模拟点击任意位置
新手必看修改DSDT教程
thinkpad t470p装黑苹果系统10.13.2
新会员