OnItemClickListener不含有ListView项按钮工作按钮、工作、OnItemClickListener、ListView

2023-09-12 07:55:33 作者:〒_〒

我有的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"

检查从的Andr​​oid定制的ListView无法详细了解此点击项目

 
精彩推荐
图片推荐