2013-07-29 44 views
5

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 #0x7f020Tà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; 
    } 

Trả lời

8

Xem liệu những gì @Nebraska đã đề xuất có giúp ích hay không.

khác, hãy thử này:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:state_checked="true" android:drawable="@android:color/white" /> 
    <item android:state_checked="false" android:drawable="@android:color/black" /> 
</selector> 
+0

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

+0

@Constantin Xong. – Vikram

+0

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

1

Trước hết, đặt chúng vào thư mục hdpi, và sau đó làm sạch dự án. Nó sẽ cập nhật mọi thứ và lỗi sẽ biến mất.

+0

Thật không may, điều này không hiệu quả. Làm sạch dự án, gỡ cài đặt ứng dụng, cùng một lỗi. – Constantin

+0

Những thứ android: màu đó có thể gặp sự cố với chúng – Nebraska

+0

Tôi sẽ chụp ảnh đó. – Constantin

Các vấn đề liên quan