我有这个代码,我需要删除在列表视图中检查的数据,但我的问题是,我只得到第一个复选框。当我检查第二个复选框时,它不检索数据。 getChildCount()也返回0为什么它是这样的?我不知道我将如何继续解决我的问题。谢谢。Android从列表视图中获取复选框的值
这里是我的代码:
btnDel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
RetailerDatabaseHelper dbHelper = new RetailerDatabaseHelper(TemplateActivity.this);
final SQLiteDatabase db = dbHelper.getReadableDatabase();
CheckBox cb = (CheckBox) findViewById(R.id.checkBox1); //For further investigation!
Cursor c10 = db.query("Retailer", new String[]{"_id", "name", "validity"}, null, null, null, null, null, null);
ListAdapter adapter = new SimpleCursorAdapter(TemplateActivity.this, R.layout.custom_dialog_box, c10, new String[]{"name", "validity"}, new int[]{R.id.checkBox1, R.id.number}, 0);
ListView myList = (ListView) findViewById(R.id.listview);
myList.setAdapter(adapter);
Log.d("Inside Button", "Test Child: " + myList.getChildCount() + " Adapter: " + adapter.getCount() + " getAdapter: " + myList.getAdapter().getCount() + " Child: " + myList.getChildAt(1));
for(int x = 0; x < myList.getAdapter().getCount(); x++)
{
View nextChild = myList.getChildAt(x);
if(nextChild instanceof CheckBox)
{
CheckBox checkbox = (CheckBox)nextChild;
if(checkbox.isChecked())
{
Toast.makeText(getApplicationContext(), "Checked", Toast.LENGTH_SHORT).show();
}
}
}
}
});
请花时间capitilise你的'我的 –