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

标签 android imagebutton expandablelistview

我正在我的应用程序中使用 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 将不会展开。有谁知道是什么问题?

编辑:好的,我明白问题出在哪里了。我有一个可聚焦的 View ,导致当我单击一行时不调用 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

最佳答案

Romain Guy 本人在 group discussion 中相当简洁地回答了您的问题.

关于android - ExpandableListView 组行中的 ImageButton 导致不触发 onClickListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6929906/

相关文章:

Android ImageButton 在 Activity 中运行良好。它在 fragment 中不起作用

android - 如何调整 imageButton 的大小?

android - 可扩展的 Listview 父项和子项单独包装在一个布局中。

java - 如何使用 CheckBox 在 ExpandableListView 中隐藏特定组

android - 如何以编程方式在自定义标题栏上设置背景颜色渐变?

android - 如何为自定义对话框设置按钮点击监听器?

java - VideoView "is loaded"监听器?

java - Android:无法实例化类:没有空构造函数

android - 可绘制作品不正确

android - 以编程方式检索 Android API 版本