我迷路了,我看不到为什么当我单击列表视图中的项目时没有执行 OnItemClickListener。我尝试将 android:focusable="false" 添加到列表视图和文本视图中。谢谢你的帮助。
clistArray = new ArrayList<CustomerList>();
clistDataAdapter = new CustomerListAdapter(this, R.layout.cus_list, clistArray);
CustView = (ListView)findViewById(R.id.allCustomerList);
OnItemClickListener cuslistener = new OnItemClickListener (){
public void onItemClick(AdapterView<?> parent, View view, int position, long id){
selectedCustomer = cusdatasource.getCustomer(String.valueOf(id));
}
}
CustView.setAdapter(clistDataAdapter);
CustView.setOnItemClickListener(cuslistener);
CustView.setItemsCanFocus(true);
列表视图.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="match_parent"
android:orientation="horizontal"
android:baselineAligned="False">
<ListView
android:id="@+id/allCustomerList"
android:layout_width="200dp"
android:layout_height="match_parent"
android:layout_weight="1" >
</ListView>
cus_list.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="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/clistStop"
style="@style/WhiteSText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/black"
android:gravity="center|center_horizontal"
android:text="123" />
<TextView
android:id="@+id/clistName"
style="@style/WhiteSText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/black"
android:gravity="left"
android:text="name kkkkk" />
<CheckBox
android:id="@+id/clistCheck"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/black"
android:textSize="20dp" />
</LinearLayout>