【发布时间】:2016-02-05 23:40:39
【问题描述】:
我遇到了一些严重的问题,我有一个列表视图,其中填充了数据库中的条目,列表视图中的每一行都有一个自定义行(TextView1|TextView2|TextView3|Checkbox)。
我要做的就是在每个复选框上放置一个侦听器,这样当它被选中时,它就会从列表视图中删除并从数据库中删除。我有一个函数可以在传递 Textview1 的值时从数据库中删除该行。
我遇到的问题是尝试从复选框甚至 textview 值中获取行 ID。我到处搜索,但仍然无法工作
复选框
Cursor cursor = db.getAllItems();
//String[] columns = new String[] {db.KEY_NAME, db.KEY_CODE, db.KEY_ROWID};
final 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.setClickable(false);
//shoppingList.setChoiceMode(shoppingList.CHOICE_MODE_SINGLE);
shoppingList.setAdapter(myCursorAdapter);
CheckBox check = (CheckBox) findViewById(R.id.checkBox1);
check.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (buttonView.isChecked()) {
//how do i get the row_id or the text view value?
} else {
//do nothing
}
}
});
【问题讨论】: