简体   繁体   中英

Toggle Switch inside custom listview makes listview non-clickable

I am working on Android application in which I am making a custom listview in which I have put some textviews and one switch. After putting toggle switch it makes listview non clickable. I have also put android:focusable="false" in my XML, but it is still not allowing listview to be clickable.

My code and XML is given below:

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

Replace

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

By

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

尝试:

android:clickable="false"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM