[英]android ExpandableListView add button setonchildclicklistener not working
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 setOnGroupClickListener过程起作用
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. 该过程setOnGroupClickListener不起作用。 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. 好像您添加到项目中的Button获得项目焦点和onClick事件一样,只需将Button focusable设置为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:descendantFocusability="blocksDescendants"
:
<ExpandableListView
android:id="@+id/treatments_expandable_list"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:descendantFocusability="blocksDescendants"
android:groupIndicator="@null"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.