SectionIndexer接口中的getPositionForSection与getSectionForPosition

来源:互联网 发布:mac movist 破解 编辑:程序博客网 时间:2024/04/27 18:12

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

对字母做索引

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);
}




阅读全文
0 0
原创粉丝点击