通讯录或者事件列表需要用到此功能,先看截图
下载地址: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)
站点信息
- 文章2305
- 用户1336
- 访客11455432
每日一句
Talent without working hard is nothing.
没有努力,天份不代表什么。
没有努力,天份不代表什么。
MySQL 数据库优化
This function has none of DETERMINISTIC, NO SQL, or READS SQL DATA in its de
免ROOT实现模拟点击任意位置
Mobaxterm终端神器
CreateProcessW要注意的细节问题
Autonomous NAT Traversal
【教程】win10 彻底卸载edge浏览器
eclipse工程基于Xposed的一个简单Hook
排名前5的开源在线机器学习
Mac OS最简单及(Karabiner)快捷键设置
发一款C++编写的麻将
VMware NAT端口映射外网访问虚拟机linux
独家发布最新可用My-AutoPost——wordpress 采集器
新会员