Tôi có một bố cục mục như thế này, và thiết lập nền bằng cách sử dụng mục chọnOnItemClickListener không hoạt động với hộp kiểm?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:background="@drawable/itemselector"
android:orientation="horizontal" >
<CheckBox
android:id="@+id/message_row_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/message_row_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:textColor="@color/black" />
itemselector.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@color/yellow" />
<item
android:state_selected="true"
android:drawable="@color/green" />
<item
android:drawable="@color/white" />
</selector>
Tôi có một ListView mà sẽ content một số mặt hàng. Sau đó, tôi đã sử dụng setOnItemClickListener() nhưng nó không hoạt động. Tôi thấy rằng nếu tôi loại bỏ các hộp kiểm trong mục, mọi thứ sẽ là okey.
Sự cố giữa hộp kiểm và người nghe ở đây là gì? Bạn có thể cho tôi một số giải pháp không?
Cập nhật: Đây là mã của người nghe
mainListView.setAdapter(messageAdapter);
mainListView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Message p = (Message) arg0.getItemAtPosition(arg2);
Toast.makeText(TarsiusActivity.this, p.getTitle(), Toast.LENGTH_LONG);
Log.i("Item Clicked", p.getTitle());
}
});
ps: Tôi muốn làm cho hộp thư như gmail trên android. Mỗi hàng có một hộp kiểm và người dùng có thể bấm vào mục nếu họ muốn nhìn thấy thông báo
Vui lòng hiển thị mã bạn đã sử dụng để đặt 'onClickListener()'. – PearsonArtPhoto
Tôi đã cập nhật mã – TrungNguyen
bản sao có thể có của [ListView OnItemClickListener Not Responding?] (Http://stackoverflow.com/questions/2367936/listview-onitemclicklistener-not-responding) –