问题描述
我有的ListView
自定义适配器
供给查看
到的ListView
以这种方式:
I have ListView
with custom Adapter
which supplies View
to ListView
in this way:
public View getView(int position, View convertView, ViewGroup parent)
{
RelativeLayout.LayoutParams lineParams;
RelativeLayout line=new RelativeLayout(context);
TextView tv=new TextView(context);
tv.setText("Text in postion="+i);
lineParams=new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lineParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
line.addView(tv, lineParams);
lineParams.addRule(RelativeLayout.CENTER_IN_PARENT);
//checkbox
CheckBox checkBox=new CheckBox(context);
lineParams=new RelativeLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lineParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
lineParams.addRule(RelativeLayout.CENTER_IN_PARENT);
line.addView(checkBox, lineParams);
return line;
}
和某处的ListView
有 setOnItemClickListener()
,这应该拦截项单击事件。我的问题是,每当我尝试添加复选框项 - 我没有得到任何responces从我的的ListView
。如果我跳过复选框
或任何其它按钮
它的工作原理。
And somewhere inside ListView
there's setOnItemClickListener()
, which should intercept item clicking events. My problem that, whenever I try to add checkbox to item - I don't get any responces from my ListView
. If I skip CheckBox
or any other Button
it works.
我真的坚持了这个问题,我已经尝试了所有类型的布局中,对齐,包装等等 - 也没用。貌似复选框
干扰的ListView
产品Click事件。
I am really stuck with this problem, I have tried all kind of Layouts, aligning, wrapping and so on - useless. Looks like CheckBox
interferes ListView
item click events.
任何想法如何克服?
推荐答案
只需添加此行到lisview
just add this line into the lisview
android:focusable="false"
检查从的Android定制的ListView无法详细了解此点击项目
这篇关于OnItemClickListener不含有ListView项按钮工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!