简体   繁体   中英

Elements in ExpandableListView are not clickable:

There is the following code:

            mListOfExistedMessages.setAdapter(new ExistedTasksExpandableListAdapter(context, persons));
            mListOfExistedMessages.setOnChildClickListener(new OnChildClickListener() {

                @Override
                public boolean onChildClick(ExpandableListView parent,
                        View v, int groupPosition, int childPosition,
                        long id) {
                    Toast.makeText(ExistedMessagesActivity.this, "1", 
                            Toast.LENGTH_LONG).show();
                    return false;
                }

            });
            mListOfExistedMessages.setItemsCanFocus(false);

ExistedTasksExpandableListAdapter is my custom adapter, and code of adapter works good (shows custom views for group and child). Code of child layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:focusable="false"
    android:orientation="horizontal"
    android:padding="10dip"
    android:paddingLeft="15dip" >

    <CheckBox
        android:id="@+id/listItemExistedMessageChecked"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center"
        android:text="" />

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1.7"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/listItemExistedMessageText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:maxLines="2"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />

        <TextView
            android:id="@+id/listItemExistedMessageRepeating"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall"
            android:textStyle="italic" />
    </LinearLayout>

    <View
        android:layout_width="5dip"
        android:layout_height="match_parent"
        android:layout_marginLeft="5dip"
        android:background="#1874CD"
        android:focusable="false"
        android:focusableInTouchMode="false" />

    <LinearLayout
        android:layout_width="0dip"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:text="Next event:"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/listItemExistedMessageDateTime"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:gravity="center"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    </LinearLayout>

</LinearLayout>

But there is no messages by child view clicking! How can I fix it?

Try to add:

    return super.onChildClick(parent, v, groupPosition, childPosition, id);

instead of false. Did this work for you?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM