我试图为自定义ArrayAdapter实现选择器可绘制资源.我一直得到一个
android.content.res.Resources $NotFoundException:来自可绘制资源ID的文件res / drawable / list_selector.xml#0x7f020
有人可以提供建议吗?
我有两个xml文件:
RES /抽拉/ 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 /布局/ 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>
最后,我的代码加载列表项,如下所示:
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建议的帮助.
否则,试试这个:
<?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>