Tôi muốn tạo một listview không thể chọn và không thể nhấp. Tôi đang nói về sự thay đổi màu sắc xảy ra khi tôi nhấp vào một mục danh sách. Mã được đưa ra dưới đây. Tôi là một newbie trong android vì vậy hãy tử tế.Làm cách nào để làm cho chế độ xem danh sách này không thể chọn được?
từ: listitem.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8px">
<TextView
android:id="@+id/label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFFFFF"/>
<TextView
android:id="@+id/data"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16px"/>
</LinearLayout>
từ: details.java
TestActionAdapter() {
super(TestDetails.this, R.layout.action_list_item, actions);
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TestAction action = actions.get(position);
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.action_list_item, parent, false);
TextView label = (TextView) view.findViewById(R.id.label);
label.setText(action.getLabel());
TextView data = (TextView) view.findViewById(R.id.data);
data.setText(action.getData());
return view;
}
hoạt động. Cảm ơn đã trả lời nhanh chóng. –
Nhưng dấu phân cách giữa các mục đã biến mất ngay bây giờ. Có cách nào để lấy lại chúng không? –
Ghi đè phương thức areAllItemsEnabled() có vẻ như xóa các ngăn xem danh sách, vì vậy chỉ ghi đè isEnabled (vị trí int) nếu bạn muốn giữ các dải phân cách của mình. –