I am trying to implement a listview with checkbox so that when a check box is checked the list row will be removed. I am populating the listview with a cursor and this is working fine and the checkbox is being displayed.
What I am having trouble with is figure out how to get the _id of the row of the box that has been checked.
Can anyone show me how to implement something like this
ListView and CheckBox
Cursor cursor = db.getAllItems();
//String[] columns = new String[] {db.KEY_NAME, db.KEY_CODE, db.KEY_ROWID};
String[] columns = new String[] {db.KEY_ITEM_NAME, db.KEY_MEASUREMENT, db.KEY_UNIT};
int[] to = new int[] {R.id.ingredientName, R.id.ingredientMeasurement, R.id.ingredientUnit};
final SimpleCursorAdapter myCursorAdapter = new SimpleCursorAdapter(this,R.layout.row4, cursor, columns, to, 0);
final ListView shoppingList = (ListView) findViewById(R.id.shoppingList);
shoppingList.setAdapter(myCursorAdapter);
CheckBox deleteCheck = (CheckBox)findViewById(R.id.checkBox1);
deleteCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
if (isChecked){
// How do I get the list item clicked to delete row?
}
}
});
Aucun commentaire:
Enregistrer un commentaire