ExpandableListView 组行中的 ImageButton 导致 onClickListener 不被触发

发布于 2024-11-27 21:00:41 字数 2178 浏览 1 评论 0原文

我正在我的应用程序中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心舞飞扬 2024-12-04 21:00:41

Romain Guy 本人在此小组讨论。

Romain Guy himself has answered your question rather succinctly in this group discussion.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文