找不到绘图资源 [英] Drawable Resource Not Found
本文介绍了找不到绘图资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试为自定义 ArrayAdapter
实现选择器可绘制资源.我一直在获取 android.content.res.Resources $ NotFoundException:可绘制资源ID#0x7f020
All I am attempting to implement a selector drawable resource for a custom ArrayAdapter
. I am consistently getting a android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020
有人可以提供建议吗?
我有两个xml文件:
res/drawable/list_selector.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
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>
最后,我的代码按如下方式加载列表项:
Finally, my code loads the list item as follows:
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;
}
推荐答案
查看@Nebraska提出的建议是否有帮助.
See if what @Nebraska has suggested helps.
否则,请尝试以下操作:
Else, try this:
<?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>
这篇关于找不到绘图资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文