wajiw
wajiw

Reputation: 12269

Android App won't hit bindView in custom simplecursoradapter

I'm kinda lost as to why my custom cursor doesn't hit the bindView override method. Any ideas?

public class ContactListSqlCursorAdapter extends SimpleCursorAdapter implements
    OnClickListener {

private Context currentContext;

public static final String TABLE_NAME = "...";

private DatabaseHelper dbHelper;
private Cursor currentCursor;
private int layout;

public ContactListSqlCursorAdapter(Context context, int layout, Cursor c,
        String[] from, int[] to, DatabaseHelper dbHelper) {

    super(context, layout, c, from, to);
    this.currentCursor = c;
    this.currentContext = context;
    this.dbHelper = dbHelper;
    this.layout = layout;

}

public View getView(int pos, View inView, ViewGroup parent) {
    View v = inView;
    if (v == null) {
        LayoutInflater inflater = (LayoutInflater) currentContext
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        v = inflater.inflate(this.layout, null);
    }

    this.currentCursor.moveToPosition(pos);
    v.setTag(Integer.parseInt(this.currentCursor
            .getString(this.currentCursor
                .getColumnIndex(DatabaseHelper.COLUMN_ID))));

    TextView txtTitle = (TextView) v.findViewById(R.id.txtTitle);
    txtTitle.setText(this.currentCursor.getString(this.currentCursor
            .getColumnIndex("ZFIRSTNAME")));

    return (v);
}

public void ClearSelections() {
    // this.dbHelper.clearSelections();
    this.currentCursor.requery();

}

@Override
public void onClick(View v) {

    CheckBox cBox = (CheckBox) v;
    Integer _id = (Integer) cBox.getTag();

    ContentValues values = new ContentValues();
    values.put(" ZHAS", cBox.isChecked() ? 1 : 0);
    this.dbHelper.shermanDB.update(this.TABLE_NAME, values, "_id='"
            + Integer.toString(_id) + "'", null);
}

@Override
public void bindView(View view, Context context, Cursor cursor) {
    ImageView imageView = (ImageView) view
            .findViewById(R.id.img_contact_photo);

    int id = currentCursor.getColumnIndex(ContactsContract.Contacts._ID);
    Uri uri = ContentUris.withAppendedId(
            ContactsContract.Contacts.CONTENT_URI, currentCursor
                    .getLong(id));

    ContentResolver cr = currentContext.getContentResolver();
    InputStream is = ContactsContract.Contacts.openContactPhotoInputStream(
            cr, uri);

    Bitmap photo = null;
     }
     }
    if (is != null) {
        photo = BitmapFactory.decodeStream(is);
    }

    if (photo != null) {
        imageView.setImageBitmap(photo);
    }

    super.bindView(view, context, cursor);
}

Activity:

            ContactsActivity.this.adapter = new ContactListSqlCursorAdapter(
                    ContactsActivity.this, R.layout.contact_list_item,
                    ContactsActivity.this.currentCursor, dbColumns,
                    listFields, ContactsActivity.this.dbHelper);
            ContactsActivity.this.lv
                    .setAdapter(ContactsActivity.this.adapter);

Upvotes: 0

Views: 1590

Answers (1)

Selvin
Selvin

Reputation: 6797

The standard CursorAdapter implementation calls newView or bindView from getView.

If you override getView, your adapter will no longer call newView/bindView.

For your records: if you extending SimpleCursorAdapter you should override getView or newView/bindView ... It is ok override all of these methods, but you should call newView/bindView from getView.

Upvotes: 3

Related Questions