I have an application where a listView custom rows is filled from a database. Each row has a CheckBox. The ListView fills up perfectly through a SimpleCursorAdapter. The issue is that when you check a CheckBox, other not visible ones are marked on the screen in the ListView. I want only the selected item to be marked and not others. I have read about this problem in the network and all the examples that they put are listView that have fixed and non-dynamic data obtained from a database. How can I solve this problem based on my code? The code I use is the following:
baseDatos = openOrCreateDatabase(nombreBD, MODE_WORLD_WRITEABLE, null);
cur = baseDatos.rawQuery("SELECT codigo AS _id, nombre, apellidos, cedula, edad, fecha, concepto, monto FROM relaciones WHERE centro= 'HCC' ORDER BY nombre ASC", null);
for(int i = 0; i < cur.getCount(); i++){
ListView listView = (ListView) findViewById(R.id.listview);
while (cur.moveToNext()){
String[] from = new String[]{"_id", "nombre", "apellidos", "cedula", "fecha", "concepto", "monto"};
int[] to = new int[]{R.id.check1, R.id.textView1, R.id.textView2, R.id.textView3, R.id.textView4, R.id.textView5, R.id.textView6};
SimpleCursorAdapter cursorAdapter = new SimpleCursorAdapter(this, row, cur, from, to);
listView.setAdapter(cursorAdapter);
}
listView.setOnItemClickListener(new AdapterView.OnItemClickListener(){
public void onItemClick(AdapterView parent, View view, int position, long id) {
// TODO Auto-generated method stub
CheckBox checkb = (CheckBox) view.findViewById(R.id.check1);
TextView text1 = (TextView) view.findViewById(R.id.textView1);
TextView text2 = (TextView) view.findViewById(R.id.textView2);
TextView text3 = (TextView) view.findViewById(R.id.textView3);
TextView text5 = (TextView) view.findViewById(R.id.textView5);
cod = checkb.getText().toString();
nomb = text1.getText().toString();
apell = text2.getText().toString();
ced = text3.getText().toString();
concep = text5.getText().toString();
Toast.makeText(getApplicationContext(), "Ha pulsado el item " + cod, Toast.LENGTH_SHORT).show();
}
});
}
I need to mark only the selected checkbox because later that data will be deleted from the bd. I do not know if I explained well. Thank you very much in advance.