0

in my android app i have a custom list view. in each row is an checkbox.

i would like to check / uncheck the checkbox with each touch on the same row and / or with an touch on a checkbox.

ListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override

public void onItemClick(AdapterView<?> parent, View view, final int position, long id) {

SelectCheckBox = (CheckBox) ListView.getChildAt(position).findViewById(R.id.SelectCheckBox);

SelectCheckBox.toggle();
            }
});

if i touch row 3, the checkbox in row 3 will be checked / unchcheck.

but how can i realize this, with an touch directly on the checkbox. i would like to give a toast feedback with "You checked Checkbox X" (X = row-number of Checkbox)

SpecialFighter
  • 523
  • 1
  • 9
  • 14
  • check this answer http://stackoverflow.com/a/24864536/1320616 – Ankit Aggarwal Jan 04 '16 at 07:12
  • In your adapter, and an `onCheckedListener` to the `CheckBox` there. – Eric B. Jan 04 '16 at 07:14
  • but how can i find the checkbox by id and set an oncheckedlistener on this, if i haven't the child position of the list view before – SpecialFighter Jan 04 '16 at 07:32
  • it depends on how you feed your list, but a trick that you could use is: in each row add a textview containing your ID or whatever you want to show in your toast. Set visibility to GONE so your list will look the same. Hence, you can retrieve the "hidden" ID when the user clicks any row – Carlos Borau Jan 04 '16 at 07:49
  • sry, but i don't understand how i can solve this problem. i know, that i have to set an general onchecklistener for my checkboxes. this check listener have to listen dynamic for this checkbox, which i have checked (for example: i checked the box in row 3. but how i can find this than via ID? – SpecialFighter Jan 04 '16 at 10:13
  • okay i found the solution. i put this onchangelistener in my adapter - how Eric told this before. thx ! – SpecialFighter Jan 04 '16 at 10:25

0 Answers0