android - 带有 horizo​​ntalScrollView OnItemClick 的 ListView 不起作用

标签 android android-listview

很快我就有了一个带有自定义适配器的 listView,它膨胀了一个包含 horizo​​ntalScrollView 以及 textview 等的 View 。我遇到的问题是,当我尝试将监听器附加到此 listView 时,它不是接收任何回调。

我认为问题与我的列表项包含拦截点击事件的 ScrollView 有关(尽管我认为它应该只拦截其他手势)。

代码...(我的列表项 xml)

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/linearMain"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"

    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/grey" >

        <TextView
            android:id="@+id/headerName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:padding="4dp"
            android:textColor="@color/text_header"
            android:textStyle="bold"
            android:text="TextView" />

    </RelativeLayout>
    <View
        android:background="@color/border"
        android:layout_width="fill_parent"
        android:layout_height="1px" />
    <HorizontalScrollView
        android:id="@+id/horizontalScrollView1"
        android:layout_width="fill_parent"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:id="@+id/linearImages"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal" 
            android:padding="4dp">
        </LinearLayout>
    </HorizontalScrollView>
    <View
        android:background="@color/border"
        android:layout_width="fill_parent"
        android:layout_height="1px" />
</LinearLayout>

然后在我的 onCreate...

lv.setAdapter(myobj.adapter);
    lv.setTextFilterEnabled(true);
    lv.setOnItemClickListener(new OnItemClickListener(){

        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                long arg3) {
            // TODO Auto-generated method stub
            Log.w("dsdsds", "sdsdsds");
        }});

如有任何帮助或建议,我们将不胜感激

最佳答案

将其添加到最顶层的布局:

android:descendantFocusability="blocksDescendants"

这对我有用,现在 onItemClickListener 被解雇了。

关于android - 带有 horizo​​ntalScrollView OnItemClick 的 ListView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9049086/

相关文章:

android - 获取在自定义适配器 ListView android中选择的项目

android - 根据列表项更改上下文菜单文本

android - 从 hashmap 获取值并添加到 listview

java - SMS 服务所需的类或接口(interface)?

java - Android Studio : Can't open file after app restarts

android - 使用 ArrayList<Object> 填充 ListView

android - 无法在 listView 中上升,因为 SwipeRefreshLayout

java - 以编程方式在 Java 中生成自签名证书 (X509)、私钥和公钥的问题

Java 线程没有运行完成,为什么?

android:如何将 xml 布局中的子项添加到自定义 View 中