Skip to content Skip to sidebar Skip to footer

Apply Custom Listview For A Cursoradapter

I am building a custom listview used to list contacts from the contact cursor into a list with two text view for the phone number and name of the contact as well as a place for th

Solution 1:

I figure it out you have to overwrite the newview and bindview methods

publicclassRowAdapterextendsCursorAdapter {

privatefinal LayoutInflater mInflater;

publicRowAdapter(Context context, Cursor c) {
super(context, c);
mInflater = LayoutInflater.from(context);

}

@OverridepublicvoidbindView(View view, Context context, Cursor cursor) {

ViewCacheviewCache=null;
ViewrowView= view;
viewCache = (ViewCache) rowView.getTag();

ImageViewimageView= (ImageView) view.findViewById(R.id.ContactIcon);
intid= cursor.getColumnIndex(HelpiDB.KEY_ID);
intnamecolumn= cursor.getColumnIndex(HelpiDB.KEY_NAME);
intnumbercolumn= cursor.getColumnIndex(HelpiDB.KEY_NUMBER);
Uriuri= ContentUris.withAppendedId(People.CONTENT_URI, cursor.getLong(id));

Bitmapbitmap= People.loadContactPhoto(context, uri, R.drawable.icon, null);

Stringname= cursor.getString(namecolumn);
Stringnumber= cursor.getString(numbercolumn);

imageView.setImageBitmap(bitmap);

TextViewnameTextView= viewCache.getName();
nameTextView.setText(name);

TextViewnumberTextView= viewCache.getNumber();
numberTextView.setText(number);
ImageViewicon= (ImageView) view.findViewById(android.R.id.icon);
booleancrossed= Boolean.valueOf(cursor.getString(HelpiDB.CHECK_COLUMN));

if (crossed) {
    icon.setImageState(newint[] { android.R.attr.state_checked }, true);

} else {
    icon.setImageState(newint[] {}, true);

}

}

@Overridepublic View newView(Context context, Cursor cursor, ViewGroup parent) {

finalViewview= mInflater.inflate(R.layout.row, parent, false);
ViewCacheviewCache=newViewCache(view);
view.setTag(viewCache);
bindView(view, context, cursor);
return view;

}

}

Post a Comment for "Apply Custom Listview For A Cursoradapter"