The following code
<TextView
android:id="@+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="20dp"
android:textSize="18sp"
android:singleLine="true" />
<TextView
android:id="@+id/lblListDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingTop="25dp"
android:textSize="12sp"
android:text="This is Desc" />
The procedure setOnGroupClickListener works
expListView.setOnGroupClickListener(new OnGroupClickListener() {
@Override
public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
Toast.makeText(getApplicationContext(), "Group Clicked " + listDataHeader.get(groupPosition), Toast.LENGTH_SHORT).show();
return true;
}
});
However, if you add a button
<TextView
android:id="@+id/lblListHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingRight="20dp"
android:textSize="18sp"
android:singleLine="true" />
<Button
android:id="@+id/iconShowParamGroup"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:background="@drawable/ic_launcher"
android:onClick="showParamGroup" />
<TextView
android:id="@+id/lblListDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="?android:attr/expandableListPreferredItemPaddingLeft"
android:paddingTop="25dp"
android:textSize="12sp"
android:text="This is Desc" />
That procedure setOnGroupClickListener does not work. And accordingly generate the following shall not be disclosed. Can you point me to a mistake?
Thank you!
Seems like the Button that you add into the item gaining the item focus and onClick event, just set the Button focusable to false. Check this:
<Button
android:id="@+id/iconShowParamGroup"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:background="@drawable/ic_launcher"
android:focusable="false"
android:onClick="showParamGroup" />
Hope this helps.
You must include the parameter android:descendantFocusability="blocksDescendants"
on your ExpandableListView :
<ExpandableListView
android:id="@+id/treatments_expandable_list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:groupIndicator="@null"/>
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.