android listview包含复选框setonItemclick无效

时间:2017-10-07 10:35:49

标签: java android xml listview

当我点击包含listview的{​​{1}}项目并选中复选框时,textview无法正常工作

这是我的java代码

android setOnItemClickListener包含复选框listview无效

setonItemclick

这是我的列表项XML代码:

 etiket_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position,
                                    long id) {
                final Database dbD = new Database(context); // Db bağlantısı oluşturuyoruz. İlk seferde database oluşturulur.
                Tags = dbD.Etiketler();
                final int  temp_id = Integer.valueOf(Tags.get(db.Etiketler().size()-position-1).get("tag_id"));
                final int pozisyon=db.Etiketler().size()-position-1;
                if (syac % 2 == 0) {
                    val_tag=val_tag+Tags.get(pozisyon).get("tag")+" ";
                    tag.setText(val_tag);
                    syac++;
                } else {
                    String newTags = tag.getText().toString().replaceAll(Tags.get(pozisyon).get("tag"),"");
                    syac++;
                    tag.setText(newTags);
                }

            }
        });          

Android <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:focusable="false" android:descendantFocusability="blocksDescendants" android:weightSum="1"> <FrameLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.09" android:background="#f8f8f8" android:descendantFocusability="blocksDescendants" android:id="@+id/item_li_frame"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceSmall" android:text="list_item_etiket2" android:id="@+id/list_item_etiket2" android:layout_gravity="left|center_vertical" android:layout_marginLeft="16dp" android:layout_marginRight="6dp" android:textColor="#4a4a4a" android:textStyle="bold" android:focusableInTouchMode="false" android:focusable="false" android:textSize="16dp" /> <CheckBox android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/etiket_checkBox" android:layout_gravity="right|center_vertical" android:focusable="false" android:focusableInTouchMode="false" android:layout_marginRight="16dp" /> </FrameLayout> </LinearLayout> 包含复选框listview无效

1 个答案:

答案 0 :(得分:0)

您已在TextView中放置了CheckBoxFrameLayout,因此checkBox位于textView之上并消耗了触摸事件。将它们放在不同的布局中,例如LinearLayout