作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
很快我就有了一个带有自定义适配器的 listView,它膨胀了一个包含 horizontalScrollView 以及 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 - 带有 horizontalScrollView OnItemClick 的 ListView 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9049086/
我是一名优秀的程序员,十分优秀!