I have a list and a checkbox in every row of it. I want that whenever I click on a row, the checkbox changes its state accordingly.
checkbox.xml
<
You need to use findViewById to get a pointer to your checkbox:
protected void onListItemClick(ListView l, View v, int position, long id) {
Toast.makeText(getApplicationContext(), "You have selected item no."
+(position+1)+"", Toast.LENGTH_SHORT).show();
super.onListItemClick(l, v, position, id);
if (v != null) {
CheckBox checkBox = (CheckBox)v.findViewById(R.id.Checkbox);
checkBox.setChecked(!checkBox.isChecked());
}
}
If you are recieving the onClick event then v should never be null but I have put on the appropriate checks.