Reputation: 171
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!
Upvotes: 1
Views: 2035
Reputation: 6422
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"/>
Upvotes: 0
Reputation: 1686
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.
Upvotes: 2