我有元素为如下包含一个复选框Listview onitemclicklistener不适用于复选框?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@color/white"
android:orientation="vertical"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:minHeight="64dp"
android:layout_marginRight="8dp"
android:layout_marginLeft="8dp"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/imageViewVoucherIcon"
android:layout_width="50dp"
android:layout_centerVertical="true"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textViewVoucherText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_toLeftOf="@+id/checkboxVoucherClick"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:textColor="@color/text"
android:text="sas"
android:layout_toRightOf="@+id/imageViewVoucherIcon" />
<CheckBox
android:id="@+id/checkboxVoucherClick"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true" />
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/seperator" />
</LinearLayout>
这是我onitem点击收听
lvVoucher.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
CheckBox cb=(CheckBox)view.findViewById(R.id.checkboxVoucherClick);
if(cb.isChecked())
{
Log.e("check","true");
}else{
Log.e("check","false");
}
}
});
不过,这并不返回任何一个列表视图。
的工作是它制定出来的? –
你想对CheckBox和其他小部件采取不同的行动吗?或者只有你想要checkBox的点击动作 – Amsheer