【问题标题】:Toggle Switch inside custom listview makes listview non-clickable自定义列表视图中的切换开关使列表视图不可点击
【发布时间】:2014-12-25 11:48:21
【问题描述】:

我正在开发 Android 应用程序,在该应用程序中我正在制作一个自定义列表视图,其中放置了一些文本视图和一个开关。放置切换开关后,它使列表视图不可点击。我还在我的 XML 中添加了android:focusable="false",但它仍然不允许单击列表视图。

我的代码和 XML 如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#fff"
    android:gravity="center_vertical"
    android:clickable="true"
    android:orientation="horizontal"
    android:padding="5dp" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center_vertical"
        android:layout_weight="1"
        android:orientation="horizontal" >

        <com.za.views.CircularImageView
            android:id="@+id/trustNetListUserImageView"
            android:layout_width="75dp"
            android:layout_height="75dp"
            android:layout_marginRight="5dp"
            android:padding="5dp"
            android:scaleType="fitXY"
            android:src="@drawable/profile_" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:orientation="vertical" >

            <TextView
                android:id="@+id/trustNetListNameTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:gravity="center_vertical"
                android:singleLine="true"
                android:text="hesds"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="#000" />

            <TextView
                android:id="@+id/trustNetListNumTextView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:singleLine="true"
                android:text="TextView" />

            <TextView
                android:id="@+id/trustNetListApprovedTextView"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="right|bottom"
                android:layout_marginRight="3dp"
                android:gravity="right"
                android:text="Approved"
                android:textColor="#ff0077"
                android:textSize="10sp" />

            <Switch
                android:id="@+id/switch1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:focusable="false"
                android:
                android:focusableInTouchMode="false"
                android:text="Switch" />

        </LinearLayout>
    </LinearLayout>

</LinearLayout>


requestListView.setAdapter(adapter);
requestListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {

                                showLoadingDialog();
                                ParseObject parseObject = requestedNetArrayList.get(arg2);
                                Constants.setOtherUserId(parseObject.getObjectId().toString());
                                Intent intent = new   Intent(TrustrkActivity.this,Othenfo.class);     
                                startActivity(intent);

                                if (parseObject.getBoolean("isApproved"))
                                    parseObject.put("isApproved", false);
                                else
                                    parseObject.put("isApproved", true);

                                parseObject.saveInBackground(new SaveCallback() {

                                    @Override
                                    public void done(ParseException e) {
                                        populateReqNetwork();
                                    }
                                });
                            }
                        });

【问题讨论】:

    标签: android listview android-togglebutton


    【解决方案1】:

    替换

    android:focusable="false"
    android:
    android:focusableInTouchMode="false"
    

    android:focusable="false"
    android:focusableInTouchMode="false"
    

    【讨论】:

      【解决方案2】:

      试试:

      android:clickable="false"
      

      【讨论】:

      • 这与添加 android:focusable="false"android:focusableInTouchMode="false" 对我有用
      • 这条线去哪儿了?
      • 所有三个 android:clickable="false"android:focusable="false"android:focusableInTouchMode="false" 都不适合我。一起或分开。
      猜你喜欢
      • 1970-01-01
      • 2015-07-26
      • 1970-01-01
      • 1970-01-01
      • 2018-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多