Tất cả tôi đang cố gắng triển khai tài nguyên có thể chọn có thể chọn cho một tùy chỉnh ArrayAdapter
. Tôi liên tục nhận được một android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020
Tài nguyên có thể rút không tìm thấy
Có ai có thể đưa ra đề xuất không?
Tôi có hai tập tin xml:
res/drawable/list_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_checked="true" android:color="@android:color/white" />
<item android:state_checked="false" android:color="@android:color/black" />
</selector>
res/layout/list_item.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/casualty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/list_selector"/>
</LinearLayout>
Cuối cùng, mã của tôi tải các mục danh sách như sau:
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
TCCC cur_object = getItem(position);
View cur_view = convertView;
if(cur_view == null)
{
System.out.println("Inflating!");
cur_view = View.inflate(getContext(), R.layout.list_item, null);
String text_value = (cur_object.m_name.length() == 0) ? "New Casualty" : cur_object.m_name;
TextView name_box = (TextView)cur_view.findViewById(R.id.casualty_text_view);
if(name_box != null)
name_box.setText(text_value);
}
return cur_view;
}
Cảm ơn bạn, các drawable đã làm nó. Vui lòng xóa gợi ý logic, nó không áp dụng cho câu hỏi. – Constantin
@Constantin Xong. – Vikram
Bất kỳ ý tưởng làm thế nào selectors làm việc btw? Tôi đang chơi xung quanh với việc thay đổi màu nền của một mục ListView trong thời gian chạy. Một cách tiếp cận là sử dụng 'setBackgroundColor()' lập trình, điều này rất dễ dàng và hiệu quả. Bộ chọn (bất ngờ) cũng hoạt động nhưng không chính xác. Nó không thiết lập màu sắc chính xác. Bất kỳ suy nghĩ về nơi tôi có thể đọc về lạm phát xem, nói cách khác là chọn chỉ sử dụng tĩnh một lần ở lạm phát hoặc liên tục? Hoặc thực hiện các cuộc gọi 'getView()' mặc định để tận dụng chúng? – Constantin