资 源 简 介
android联系人带字母检索源码/** * 联系人列表适配器。 * * @author guolin */public class ContactAdapter extends ArrayAdapter { /** * 需要渲染的item布局文件 */ private int resource; /** * 字母表分组工具 */ private SectionIndexer mIndexer; public ContactAdapter(Context context, int textViewResourceId, List objects) { super(context, textViewResourceId, objects); resource = textViewResourceId; } @Override public View getView(int position, View convertView, ViewGroup parent) { Contact contact = getItem(position); LinearLayout layout = null; if (convertView == null) { layout = (LinearLayout) LayoutInflater.from(getContext()).inflate(resource, null); } else { layout = (LinearLayout) convertView; } TextView name = (TextView) layout.findViewById(R.id.name); LinearLayout sortKeyLayout = (LinearLayout) layout.findViewById(R.id.sort_key_layout); TextView sortKey = (TextView) layout.findViewById(R.id.sort_key); name.setText(contact.getName()); int section = mIndexer.getSectionForPosition(position); if (position == mIndexer.getPositionForSection(section)) { sortKey.setText(contact.getSortKey()); sortKeyLayout.setVisibility(View.VISIBLE); } else { sortKeyLayout.setVisibility(View.GONE); } return layout; } /** * 给当前适配器传入一个分组工具。 * * @param indexer */ public void setIndexer(SectionIndexer indexer) { mIndexer = indexer; }}