自定义列表视图中的切换开关使列表视图无法点击

时间:2014-12-25 11:48:22

标签: android listview android-togglebutton

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

我的代码和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();
                                    }
                                });
                            }
                        });

2 个答案:

答案 0 :(得分:2)

替换

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

通过

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

答案 1 :(得分:2)

尝试:

android:clickable="false"