I decided not to use SimpleCursorAdapter for populating listview as in Notepad code sample :
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.noteslist_item, cursor,
new String[] { NoteColumns.TITLE }, new int[] { android.R.id.text1 });
setListAdapter(adapter);
Instead i'm using custom cursor adapter:
MyAdapter items = new MyAdapter(this, c);
setListAdapter(items);
}
private class MyAdapter extends ResourceCursorAdapter {
public MyAdapter(Context context, Cursor cur) {
super(context, R.layout.list_item, cur);
}
@Override
public View newView(Context context, Cursor cur, ViewGroup parent) {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return li.inflate(R.layout.list_item, parent, false);
}
@Override
public void bindView(View view, Context context, Cursor cur) {
TextView tvQuantityText = (TextView)view.findViewById(R.id.txtQuantity);
TextView tvListText = (TextView)view.findViewById(R.id.text1);
CheckBox cbListCheck = (CheckBox)view.findViewById(R.id.chkIsDone);
tvListText.setText(cur.getString(cur.getColumnIndex(DBAdapter.KEY_TITLE)));
tvQuantityText.setText(cur.getString(cur.getColumnIndex(DBAdapter.KEY_QUANTITY)));
cbListCheck.setChecked((cur.getInt(cur.getColumnIndex(DBAdapter.KEY_ISDONE))==0? false:true));
final int rowID = cur.getInt(cur.getColumnIndex(DBAdapter.KEY_ROWID));
//checkbox click
cbListCheck.setOnClickListener( new View.OnClickListener() {
public void onClick(View v) {
CheckBox cb = (CheckBox) v ;
SaveDone(cb.isChecked(), v.getContext(), rowID);
}
});
}