SectionIndexer接口中的getPositionForSection与getSectionForPosition

xiaoxiao2021-02-28  5

今天学习写联系人列表时遇到的问题-

对字母做索引

public int getPositionForSection(int section) {

// 通过首字母section对应显示的position位置 // 循环遍历所有联系人数据 for(int i=0;i<contacts.size();i++){ //找到当次循环时,联系人名字的首字母 int ch=contacts.get(i).pinyin.toUpperCase(Locale.CHINA).charAt(0); if(ch==section){

return i;

}

}

return 0;

}

public int getSectionForPosition(int position) { //获取position位置对应的首字母section return contacts.get(position).pinyin.toUpperCase(Locale.CHINA).charAt(0); }

转载请注明原文地址: https://www.6miu.com/read-1150307.html

最新回复(0)