gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:01:42 25 4
gpt4 key购买 nike

很快我就有了一个带有自定义适配器的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com