android – 找不到可绘制的资源

前端之家收集整理的这篇文章主要介绍了android – 找不到可绘制的资源前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我试图为自定义ArrayAdapter实现选择器可绘制资源.我一直得到一个 android.content.res.Resources $NotFoundException:来自可绘制资源ID的文件res / drawable / list_selector.xml#0x7f020

有人可以提供建议吗?

我有两个xml文件

RES /抽拉/ list_selector.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android" >
  3. <item android:state_checked="true" android:color="@android:color/white" />
  4. <item android:state_checked="false" android:color="@android:color/black" />
  5. </selector>

RES /布局/ list_item.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="horizontal" >
  6.  
  7. <TextView
  8. android:id="@+id/casualty_text_view"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:background="@drawable/list_selector"/>
  12.  
  13. </LinearLayout>

最后,我的代码加载列表项,如下所示:

  1. public View getView(int position,View convertView,ViewGroup parent) {
  2. // TODO Auto-generated method stub
  3. TCCC cur_object = getItem(position);
  4.  
  5. View cur_view = convertView;
  6. if(cur_view == null)
  7. {
  8. System.out.println("Inflating!");
  9. cur_view = View.inflate(getContext(),R.layout.list_item,null);
  10. String text_value = (cur_object.m_name.length() == 0) ? "New Casualty" : cur_object.m_name;
  11.  
  12. TextView name_Box = (TextView)cur_view.findViewById(R.id.casualty_text_view);
  13. if(name_Box != null)
  14. name_Box.setText(text_value);
  15. }
  16.  
  17. return cur_view;
  18. }

解决方法

看看@Nebraska建议的帮助.

否则,试试这个:

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

猜你在找的Android相关文章