首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >找不到可绘制的资源

找不到可绘制的资源
EN

Stack Overflow用户
提问于 2013-07-30 07:16:13
回答 5查看 22K关注 0票数 14

我正在尝试为一个自定义ArrayAdapter实现一个选择器可抽出的资源。我一直都在使用android.content.res.Resources$NotFoundException: File res/drawable/list_selector.xml from drawable resource ID #0x7f020

有没有人能提点建议?

我有两个xml文件:

res/drawable/list_selector.xml

代码语言:javascript
复制
<?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

代码语言:javascript
复制
<?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>

最后,我的代码按如下方式加载列表项:

代码语言:javascript
复制
    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;
    }
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17935813

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档