问题描述
所以我真的很快有了一个带有自定义适配器的listView,它使包含一个HorizontalScrollView以及textview等的视图膨胀.我遇到的问题是,当我尝试将侦听器附加到此listView时,它不是接收任何回调.
So really quickly i have a listView with a custom adapter and it inflates a view that contains a horizontalScrollView as well as a textview etc. The problem I am having is that when i try to attach a listener to this listView it is not receiving any callbacks.
我认为问题与以下事实有关:我的列表项包含一个滚动视图,该滚动视图正在拦截click事件(尽管我认为它应该只拦截其他手势).
I believe the problem has to do with the fact that my list item contains a scroll view which is intercepting the click events (although i thought it should only intercept other gestures).
代码...(我的列表项xml)
code... (my list item 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中...
and then in my 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");
}});
任何帮助或建议,将不胜感激
Any help or suggestions would be greatly appreciated
推荐答案
将此添加到最顶层的布局中:
Add this to the topmost Layout:
android:descendantFocusability="blocksDescendants"
现在我的onItemClickListener被解雇了,这对我来说是成功的秘诀.
It did the trick for me, now onItemClickListener is being fired.
这篇关于具有HorizontalScrollView OnItemClick的ListView不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!