ExpandableListView 组行中的 ImageButton 导致 onClickListener 不被触发
我正在我的应用程序中使用 ExpandableListView。它工作得很好,直到我决定在它的末尾添加一个 ImageButton。这是我的 XML:
这是我的组行:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:text="location"
android:layout_height="45dp"
android:layout_width="250dp" style="@style/listResultsTitle"
android:id="@+id/results_location_row"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="40dp">
</TextView>
<TextView
android:text="ad"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="30dp"
android:layout_width="wrap_content"
style="@style/listResults"
android:id="@+id/results_ad_row"
android:layout_alignBottom="@+id/results_location_row"
android:layout_alignLeft="@+id/results_location_row"
android:layout_alignRight="@+id/results_location_row">
</TextView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prox_order"
android:src="@drawable/ic_menu_add"
android:background="@android:color/transparent"
android:layout_centerVertical="true"
android:layout_alignParentRight="true">
</ImageButton>
现在,ExpandableListView 将不会展开。有谁知道问题可能是什么?
编辑:好的,我明白问题是什么。我有一个可聚焦的视图,导致当我单击一行时不会调用 onItemClickListener。我实现了一个 onClickListener 来捕获单击,但我不知道如何展开该行。有人可以帮忙吗?这是我的自定义适配器内部的代码:
v.setOnClickListener(new OnItemClickListener(groupPosition, this))
private class OnItemClickListener implements OnClickListener{
private int pos;
MySimpleExpandableListAdapter adapter;
OnItemClickListener(int groupPosition, MySimpleExpandableListAdapter _adapter){
pos = groupPosition;
adapter = _adapter;
}
@Override
public void onClick(View v) {
Log.e("Adapter", "Row clicked: #" + String.valueOf(pos));
}
}
~Nemisis7654
I am working with an ExpandableListView in my application. It worked fine until I decided to add an ImageButton to the end of it. Here is my XML:
This is my group row:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1">
<TextView
android:text="location"
android:layout_height="45dp"
android:layout_width="250dp" style="@style/listResultsTitle"
android:id="@+id/results_location_row"
android:gravity="center_vertical"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="40dp">
</TextView>
<TextView
android:text="ad"
android:textAppearance="?android:attr/textAppearanceSmall"
android:layout_height="30dp"
android:layout_width="wrap_content"
style="@style/listResults"
android:id="@+id/results_ad_row"
android:layout_alignBottom="@+id/results_location_row"
android:layout_alignLeft="@+id/results_location_row"
android:layout_alignRight="@+id/results_location_row">
</TextView>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/prox_order"
android:src="@drawable/ic_menu_add"
android:background="@android:color/transparent"
android:layout_centerVertical="true"
android:layout_alignParentRight="true">
</ImageButton>
Now, the ExpandableListView will not expand. Does anyone know what the problem could be?
EDIT: Okay, I understand what the problem is. I have a view that is focusable that causes the onItemClickListener not to be called when I click on a row. I implemented an onClickListener that captures the click, but I do not know how to expand the row. Can anyone help out? Here is the code that I have inside of my custom Adapter:
v.setOnClickListener(new OnItemClickListener(groupPosition, this))
private class OnItemClickListener implements OnClickListener{
private int pos;
MySimpleExpandableListAdapter adapter;
OnItemClickListener(int groupPosition, MySimpleExpandableListAdapter _adapter){
pos = groupPosition;
adapter = _adapter;
}
@Override
public void onClick(View v) {
Log.e("Adapter", "Row clicked: #" + String.valueOf(pos));
}
}
~Nemisis7654
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Romain Guy 本人在此小组讨论。
Romain Guy himself has answered your question rather succinctly in this group discussion.