Deam
Deam

Reputation: 1007

onChildClick does not work for my ExpandableListView

I am unable to know the reason that why the heck onChildClick of my ExpandableListView is not working. But onGroupClick works as it should.

here is what I have

fileExpandableList.setOnGroupClickListener(this);
            fileExpandableList
                .setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
                @Override
                public boolean onChildClick(ExpandableListView parent,
                        View v, int groupPosition, int childPosition,
                        long id) {
                    System.out.println("Child CLICKED.");
                    return false;
                }

            });

I have seen many people having this problem but no one had conclusive answer.

ADDED:

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}

list view xml:

...
        <ExpandableListView
        android:id="@android:id/list"
        android:drawSelectorOnTop="false"
        android:groupIndicator="@drawable/group_indicator"
        style="@style/allWrapper" >
    </ExpandableListView>
</FrameLayout>

child row xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/expandablelist_childrow"
style="@style/allmenu" >

<com.abc.xyz.android.view.TypeModuleView
    android:id="@+id/expandablelist_childview"
    android:longClickable="true"
    android:onClick="myOnClick"
    style="@style/module" >
</com.abc.xyz.android.view.TypeModuleView>

myOnClick event handler

    public void myOnClick(View view) {
    TypeModule clickedModule = ((TypeModuleView) view).onClick();
    if (clickedModule != null) { // In landscape layout
        moduleContentFragment.setModuleParent(clickedModule);
        moduleContentFragment.changePath("/");
        // Added for module highlighting
        expandableListFragment.setChildrenBackground(view);

    }
}

Upvotes: 1

Views: 3749

Answers (2)

Alaeddine Zidi
Alaeddine Zidi

Reputation: 556

Try to put the return value to True of isChildSelectable()

Upvotes: 4

njzk2
njzk2

Reputation: 39397

There is a conflict between the onClick attribute (why did you put it anyway ?) and the onChildClickListener.

The onClick captures the click event on the TypeModuleView. The LinearLayout doesn't receive it, and the child is not clicked.

Upvotes: 0

Related Questions