【问题标题】:android listview contains checkbox setonItemclick not workingandroid listview包含复选框setonItemclick不起作用
【发布时间】:2017-10-07 10:35:48
【问题描述】:

当我单击包含textview 和复选框的listview 项目时,setOnItemClickListener 不起作用

这是我的java代码

android listview 包含复选框 setonItemclick 不起作用

 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);
                }

            }
        });          

这是我的列表项 XML 代码:

<?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>

Android listview 包含复选框 setonItemclick 不起作用

【问题讨论】:

    标签: java android xml listview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多