Có thể sử dụng OnItemClickListener trên ListView khi bố cục Mặt hàng có tiện ích con có thể nhấp/chỉnh sửa được (RadioButton, EditText hoặc CheckBox) không?ListView với tiện ích có thể nhấp/chỉnh sửa
Trả lời
Bạn có thể muốn xem this issue. Có một mục có thể đặt tiêu điểm trong một hàng của một ListView
làm cho số OnItemClickListener
KHÔNG được gọi. Tuy nhiên, điều đó không có nghĩa là bạn không thể có các mục có thể có tiêu điểm/có thể nhấp trong một hàng, có một số cách giải quyết như this one.
Ngoài ra, bạn có thể xem qua màn hình Nhật ký cuộc gọi. Nó có một ListView
với mục có thể nhấp (biểu tượng cuộc gọi ở bên phải). See Source code here
Trợ giúp nhanh: "Một cách dễ dàng để giải quyết vấn đề này là gọi " setDescendantFocusability (FOCUS_BLOCK_DESCENDANTS); " trên danh sáchXem chế độ xem khi chúng được thêm. Bạn sẽ có thể chọn hàng, nhấp vào hàng và nhấp vào hộp kiểm và nút con. " - Đây là câu trích dẫn từ nhận xét số 27 trong trang được đề cập bởi hai trong số các liên kết trong câu trả lời ở trên. Cám ơn rất nhiều!! –
Liên kết đến giải pháp 1 bị hỏng. Ai đó có thể chỉnh sửa điều này? – Martze
chỉ liên kết đầu tiên đang hoạt động với những người khác bị hỏng, vui lòng sửa lại – BBdev
Trích dẫn comment # 31 trong liên kết được đề cập bởi Samuh (mà giải quyết được vấn đề đối với tôi):
Trong thực tế, bạn có thể thêm nó vào XML layout (nếu thổi phồng bởi một): android: descendantFocusability = "blocksDescendants".
Thêm vào đây JIC trang web đó sẽ ngừng hoạt động trong tương lai.
Nếu bất kỳ mục hàng nào trong danh sách chứa chế độ xem có thể lấy tiêu điểm hoặc có thể nhấp thì OnItemClickListener
sẽ không hoạt động.
hàng mục phải có param như android:descendantFocusability="blocksDescendants"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants"
android:gravity="center_vertical" >
// your other widgets here
</LinearLayout>
thử nhiều giải pháp phức tạp, nhưng nó là một trong những đơn giản nhất mà làm việc:
android: đặt tiêu điểm = "false"
<CheckBox
android:id="@+id/fav_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="false" />
Hai giải pháp tốt nhất
- Thêm
android:descendantFocusability="beforeDescendants"
để ListView trong xml HOẶC - Set cho hai thuộc tính để
false
như
android:focusable="false"
android:focusableInTouchMode="false"
Sau đó, nó sẽ xử lý các con mục ListView hàng (Button, EditText vv) sự kiện thay vì listView.setOnItemClick.
Tôi đã khắc phục sự cố của mình khác nhau, trong mục của tôi có nhiều hơn một LinearLayout vì vậy nếu bạn đặt id cho linearayout và setOnclickListener trong lớp bộ điều hợp thì nó sẽ hoạt động, chỉ có hiệu ứng chạm gốc sẽ biến mất. nhưng liên kết này Making a LinearLayout act like an Button rất hữu ích để làm hành động linearlaout nút như trên nhấp chuột
mục
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp">
<TextView
android:id="@+id/txt_item_followers_name"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="center|start"
android:paddingLeft="15dp"
android:text="Ali"
android:textAppearance="?android:attr/textAppearanceMedium" />
<ImageView
android:id="@+id/imageView"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentStart="true"
android:layout_below="@+id/txt_item_followers_name"
android:layout_marginLeft="10dp"
android:src="@drawable/puan_icon" />
<TextView
android:id="@+id/txt_item_followers_mark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView"
android:layout_toEndOf="@+id/imageView"
android:background="@color/red_400"
android:paddingLeft="10dp"
android:text="25.5"
android:textAppearance="?android:attr/textAppearanceSmall" />
<LinearLayout
android:id="@+id/linear_one"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/txt_item_followers_name"
android:background="@color/red_400"
android:orientation="vertical">
<ImageView
android:id="@+id/btn_item_followers_2b_follow"
android:layout_width="100dp"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_marginLeft="10dp"
android:src="@drawable/follow_buton" />
</LinearLayout>
</RelativeLayout>
bên trong phương pháp getView
@Override
public View getView(final int position, View convertView,
ViewGroup parent) {
View view = convertView;
if (convertView == null)
view = inflater.inflate(R.layout.deneme, null);
final Followers2 myObj = myList.get(position);
LinearLayout linear_one = (LinearLayout) view.findViewById(R.id.linear_one); // HERE WE DOMUNİCATE IT
linear_one.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(parentActivity, "One Two", Toast.LENGTH_SHORT).show();
}
});
TextView name = (TextView) view.findViewById(R.id.txt_item_followers_name);
TextView mark = (TextView) view.findViewById(R.id.txt_item_followers_mark);
final ImageView btn_follow = (ImageView) view.findViewById(R.id.btn_item_followers_2b_follow);
name.setText(myObj.getName());
mark.setText(myObj.getScore());
/* if (myObj.isFollow() == true) {
btn_follow.setImageResource(R.drawable.following_buton);
} else {
btn_follow.setImageResource(R.drawable.follow_buton);
}
btn_follow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Followers2 myObj = myList.get(position);
if (myObj.isFollow() == true) {
btn_follow.setImageResource(R.drawable.following_buton);
} else {
btn_follow.setImageResource(R.drawable.follow_buton);
}
}
});*/
return view;
}
- 1. Thực hiện ListView trong tiện ích màn hình chính
- 2. Điền ListView trong tiện ích màn hình chính trong Android
- 3. Tiện ích con có thể có một ngữ cảnh không?
- 4. Quản lý tiện ích từ màn hình chỉnh sửa trang
- 5. Wordpress - hiển thị tiện ích cụ thể
- 6. Tôi có thể lấy tiện ích cabarc ở đâu?
- 7. Android, cử chỉ trên các tiện ích có thể nhấp
- 8. Tiện ích WPF hữu ích
- 9. LibGDX và ScrollPane với nhiều tiện ích
- 10. Tiện ích Qt Nhanh so với Qt
- 11. PyQt - hiển thị tiện ích ở đầu tiện ích
- 12. QSplitter với một tiện ích kích thước cố định và một tiện ích kích thước biến?
- 13. Backbone.js Tiện ích
- 14. Tiện ích Javascript 3D Graphing?
- 15. jQuery trong tiện ích
- 16. Tkinter có tiện ích bảng không?
- 17. Tiện ích Diff có nghĩa là C++
- 18. Tiện ích con Android không cập nhật - có ID tiện ích không chính xác
- 19. Tiện ích vá đồ họa
- 20. Có nhiều tiện ích jQuery Autocomplete không?
- 21. GWT có tiện ích con Đoạn không?
- 22. Hoạt động bắt đầu của Android khi nhấn tiện ích ListView item
- 23. Có thể ghi đè url (với tham số phụ) bằng tiện ích mở rộng của Chrome
- 24. jQuery tương đương với tiện ích YUI StyleSheet?
- 25. Khôi phục tương tác với Tiện ích mở rộng Git
- 26. jQuery có thể sửa đổi CSS cho một loại phương tiện cụ thể không?
- 27. id tiện ích twitter động
- 28. AngularJS cách liên kết dữ liệu với tiện ích SVG
- 29. Tiện ích javascript riêng tư
- 30. Tiện ích so sánh tệp
Mở rộng ListActivity thay vì hoạt động. tham khảo http://www.softwarepassion.com/android-series-custom-listview-items-and-adapters/ –