0

I have a ListView with a onItemClickListener attached. Inside that ListView I have some rows, each with a CheckBox.

The problem is: when I click the CheckBox the Listener who answer is the onItemClickListener attached to the list. Instead I want the onCheckedChagedListener attached to the CheckBox to answer.

I've tried to put

android:descendantFocusability="blocksDescendants"

on root item or my row layout, I've also tried to use the variants afterDescendants and beforeDescendants, but none of them help me achieve what I want.

I also went through some answers on Stackoverflow and elsewhere but I can't get rid of it...

How can I be able to have both listeners, one on CheckBox only and one on whole row?

1
  • 1
    where you set listener for CheckBox? have you tried to set onCheckedChangeListener inside of onItemClick? if no, I suggest you to try, because in my case worked properly. Commented Apr 10, 2015 at 16:07

3 Answers 3

1

Try this code, should help.

@Override
public void onItemClick(AdapterView<?> parent, View itemClicked, int position, long id){
    CheckBox cbx = (CheckBox)itemClicked.findViewById(R.id.cbxList);
    cbx.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked){

        }
   });
}
Sign up to request clarification or add additional context in comments.

2 Comments

I've tried your solution, but it doesn't work: neither the CheckBox nor the whole row now respond to the click event.
previously you said that onItemClickListener responds... so does it? Anyways, for more particular problem solving need to see your code.
0

your checkbox shouldn't get whole of row and you should set android:focusable="false" to your checkbox and in your Adapter you should set OnCheckedChangeListener to your checkbox.

Comments

0

Add these both android:clickable & android:focusable and set them to false.

<CheckBox
    android:id="@+id/checkBox1"
    android:layout_width="25dp"
    android:layout_height="25dp"
    android:clickable="false"        
    android:focusable="false" 

    >
</CheckBox>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.