文字列配列を持つリストビュー用のカテゴリセクションインデクサを作成するにはどうすればよいですか?私はアルファベットインデクサーの例を見てきましたが、それはどのようにカテゴリのために実装されていますか?セクション1、セクション2、セクション3 ...?ここでの回答のアンドロイドセクションの索引チュートリアル?
2
A
答えて
3
4
はあなたの必要性やセット用としてのアダプタとしてこれをカスタマイズしますあなたのリストビューthatsすべてにリストビューでM here
public class ContactsAdapter extends BaseAdapter implements SectionIndexer {
Context context;
String[] strings;
String[] sections ;
HashMap<String, Integer> alphaIndexer;
public ContactsAdapter(Context context, String[] strings) {
this.context = context;
this.strings = strings;
alphaIndexer = new HashMap<String, Integer>();
int size = strings.length;
for (int x = 0; x < size; x++) {
String s = strings[x];
String ch = s.substring(0, 1);
ch = ch.toUpperCase();
if (!alphaIndexer.containsKey(ch))
alphaIndexer.put(ch, x);
}
Set<String> sectionLetters = alphaIndexer.keySet();
ArrayList<String> sectionList = new ArrayList<>(sectionLetters);
Collections.sort(sectionList);
sections = new String[sectionList.size()];
sectionList.toArray(sections);
}
@Override
public int getCount() {
return strings.length;
}
@Override
public Object getItem(int position) {
return strings[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
convertView = LayoutInflater.from(context).inflate(R.layout.main, parent, false);
holder = new ViewHolder();
holder.text = (TextView) convertView.findViewById(R.id.tv_contact);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.text.setText(strings[position]);
return convertView;
}
@Override
public Object[] getSections() {
return sections;
}
@Override
public int getPositionForSection(int sectionIndex) {
return alphaIndexer.get(sections[sectionIndex]);
}
@Override
public int getSectionForPosition(int position) {
return 0;
}
static class ViewHolder {
TextView text;
}
}
が
ContactsAdapter contactsAdapter = new ContactsAdapter(Registration.this, YOUR_Array;
listview.setAdapter(contactsAdapter);
listview.setFastScrollEnabled(true);
関連する問題
- 1. 画面チュートリアルの検索javascript library
- 2. oracleの索引:
- 3. SQLiteの:索引
- 4. 完全チュートリアルRuby on Railsオートコンプリート検索?
- 5. ビット列の索引
- 6. リストの索引Python
- 7. アルファベット順の索引
- 8. MongoDB:索引、ソート
- 9. カーソル索引オフアウトセクション
- 10. NoSQL:索引付けとキーワードベースの検索
- 11. 個人用ナレッジベースファイルの索引検索ツール
- 12. リストの索引を検索する
- 13. Solr索引付け -
- 14. 範囲索引MarkLogic
- 15. フィールド索引構成
- 16. PILイメージの索引付け
- 17. ENUMデータ型の索引
- 18. 逆索引のファイル形式
- 19. MySQLテーブルの索引付け
- 20. SQL結合の索引
- 21. HDFSシーケンスファイルの索引付け
- 22. アルファベット順の索引(即時)
- 23. アルファベット索引での追加
- 24. SSISタスクの索引調整
- 25. エンティティの索引付け
- 26. 索引ビューへのマテリアライズド・ビュー
- 27. 索引作成のパフォーマンス
- 28. パンダ多列索引のインデックス
- 29. C++での引数検索
- 30. サブマトリクスの索引付けR
は私が何かをやっている似HERE http://stackoverflow.com/questions/10224233/alphabetindexer-with-custom-adapter-managed-by-loadermanager – toobsco42
[これをチェック](http://androidcustomviews.com/portfolio-category/custom-views/) –