Skip to content Skip to sidebar Skip to footer

Android: Checkbox In Expandablelistview Not Triggering Onchildclick Even With Focusable=false

Goal: I am trying to create a UI with 2 checkboxes per line, each line seperated into sections. I've included a screenshot of the UI below. Current approach: I am using an Expandab

Solution 1:

You are missing a line in your XML I bet.

You need to have these two lines in your xml (the second one being the most important):

android:focusable="false"android:focusableInTouchMode="false"

That will allow each checkbox to be clickable separately as well as the row itself.

Then you set onCheckChangedListener listeners in your adapter getView() to deal with the checkboxes (where it will have access to the position, view and parent info). Your onChildClick can then deal with the rwo clicks.

Solution 2:

As far as I figured it out, the checkbox does consume the event so the OnChildClickListener doesn't trigger. In the tag list item I added these lines to the checkbox:

<CheckBox...android:focusable="false"android:clickable="false"android:focusableInTouchMode="false"/>

Then I could simply use my OnChildClickListener as if I wouldn't have used a checkbox.

Solution 3:

I think it's because the checkbox consumes the event and doesn't forward it to the list item.

If you want to get the click on the boxes you can add OnClickListener to the boxes in the getView() of the list adapter.

I understand you right, the box is at least getting checked? If you don't need custom behaviour you just can read if the box is checked or not when you "submit" the list (or whatever is your next step of checking boxes).

After reading comments, here is your code example with some additions:

@Overridepublic View getView(finalint pos, final View convView, ViewGroup parent) {

    //initialize convView, define other local variables, etc. CheckBoxcb= (CheckBox) convView.findViewById(R.id.mycheckbox);
    cb.setOnCheckedChangeListener(newOnCheckedChangeListener() { 

        publicvoidonCheckedChanged(CompoundButton buttonView, boolean isChecked) { 
            Log.d("ElistCBox2", "listitem position: " + pos); 
        } 
    });

    return convView;
}

Note that you have to use final modifier for the variables which you use in the anonymous class, otherwise you get a compiler error.

Post a Comment for "Android: Checkbox In Expandablelistview Not Triggering Onchildclick Even With Focusable=false"