How does bindView() method works in Android SimpleCursorAdapterClass

4.1k Views Asked by At

I am new to Android. I implemented a ListView scrollable application by following a tutorial. But I can't understand how is bindView() method in SimpleCursorAdapter class worked when scrolling the list.

@Override
public void bindView(View view, Context context, Cursor cursor) {

    super.bindView(view, context, cursor);

    ViewHolder holder = (ViewHolder) view.getTag();
    if (holder == null) {
        holder = new ViewHolder();
        holder.colImp = cursor.getColumnIndexOrThrow(RemindersDbAdapter.COL_IMPORTANT);
        holder.listTab = view.findViewById(R.id.row_tab);
        view.setTag(holder);
    }

    if (cursor.getInt(holder.colImp) > 0) {
        holder.listTab.setBackgroundColor(context.getResources().getColor(R.color.orange));
    } else {
        holder.listTab.setBackgroundColor(context.getResources().getColor(R.color.green));
    }
}

static class ViewHolder {
    //store the column index
    int colImp;
    //store the view
    View listTab;
}
0

There are 0 best solutions below