我正在开发 Android 应用程序,在该应用程序中我制作了一个自定义列表视图,其中放置了一些文本视图和一个开关。放置切换开关后,它使列表视图不可点击。我也放入android:focusable="false"
了我的 XML,但它仍然不允许列表视图是可点击的。
我的代码和 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();
}
});
}
});