我有一个自定义适配器。在我的getView()
中,我试图用我的联系人列表填充“holder.contact”,但没有成功。我确实有这种ListView
使用联系人填充我的方法,但它破坏了我的CheckBoxes
. 这段代码不在我的CustomAdapter
课上:
public void populateContactList() {
// Build adapter with contact entries
Cursor cursor = getContacts();
String[] fields = new String[] {
ContactsContract.Data.DISPLAY_NAME
};
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.contact_entry, cursor,
fields, new int[] {R.id.contactEntryText});
lv.setAdapter(adapter);
} // END POPULATECONTACTLIST
public Cursor getContacts()
{
// Run query
Uri uri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = new String[] {
ContactsContract.Contacts._ID,
ContactsContract.Contacts.DISPLAY_NAME
};
String selection = ContactsContract.Contacts.IN_VISIBLE_GROUP + " = '" +
(false ? "0" : "1") + "'";
String[] selectionArgs = null;
String sortOrder = ContactsContract.Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC";
return managedQuery(uri, projection, selection, selectionArgs, sortOrder);
} // END GETCONTACTS
但我试图在这里定义它,但没有成功(自定义适配器类):
@Override
public View getView(final int position, View convertView, ViewGroup parent)
{
View rowView = convertView;
ViewHolder holder = null;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater)context.getSystemService(
Context.LAYOUT_INFLATER_SERVICE);
// HERE I AM INFLATING LISTVIEW LAYOUT.
rowView = inflater.inflate(R.layout.contact_entry, null, false);
holder = new ViewHolder();
holder.photo = (ImageView) rowView.findViewById(R.id.iv_contactPic);
holder.contact = (TextView) rowView.findViewById(R.id.contactEntryText);
holder.tv = (TextView) rowView.findViewById(R.id.SMSCounttext);
holder.cb = (CheckBox) rowView.findViewById(R.id.cb_contactHistoryChk);
rowView.setTag(holder);
} else {
holder = (ViewHolder) rowView.getTag();
}
有没有办法在里面应用我的 populateContactList()方法getView()
?
我的构造函数看起来像这样。“元素”已被另一个文本视图使用:
public CustomAdapter(Context context, int type, ArrayList<String> elements){
super(context, type, elements);