Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 调用setImageResource不在res/drawable中显示图像_Android_Android Listview_Android Imageview - Fatal编程技术网

Android 调用setImageResource不在res/drawable中显示图像

Android 调用setImageResource不在res/drawable中显示图像,android,android-listview,android-imageview,Android,Android Listview,Android Imageview,我在res/drawable中有许多jpeg图像,我正在尝试根据数据库行id动态查找图像,并在“ListView”中的ImageView中显示相应的图像 以下是ListView中每一行的xml布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="f

我在
res/drawable
中有许多jpeg图像,我正在尝试根据数据库行id动态查找图像,并在“ListView”中的
ImageView
中显示相应的图像

以下是ListView中每一行的xml布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/list_selector"
    android:orientation="horizontal"
    android:padding="5dip" >

   <!--  ListRow Left side Thumbnail image -->
    <LinearLayout android:id="@+id/thumbnail"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="3dip"
        android:layout_alignParentLeft="true"
        android:background="@drawable/image_bg"
        android:layout_marginRight="5dip">

        <ImageView
            android:id="@+id/list_image"
            android:layout_width="50dip"
           android:layout_height="50dip"/>

    </LinearLayout>

<!-- Title -->
<TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/thumbnail"
    android:layout_toRightOf="@+id/thumbnail"
    android:textColor="#040404"
    android:typeface="sans"
    android:textSize="15dip"
    android:textStyle="bold"/>

<!-- Author -->
<TextView
    android:id="@+id/author"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/title"
    android:textColor="#343434"
    android:textSize="10dip"
    android:layout_marginTop="1dip"
    android:layout_toRightOf="@+id/thumbnail" />


 <!-- Rightend Arrow -->
 <ImageView android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/arrow"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"/>
有人能告诉我为什么图像没有正确加载,以及我如何修复它吗

private int lookupResourceId(Context context, String id) {
        String resourceName =  "thumb_"+id;
        return context.getResources().getIdentifier(resourceName, "drawable", context.getPackageName());
    }

尝试忽略扩展。

lookupResourceId是否返回有效的资源id?你查过了吗?你查对了,阿什!它现在正在进行这一改变。:)谢谢我很好奇android会如何区分那些只在扩展名上有所不同的文件名?嗯,这真的很有趣,在今天结束之前会对其进行一些研究,并肯定会在这里发布。
private int lookupResourceId(Context context, String id) {
        String resourceName =  "thumb_"+id;
        return context.getResources().getIdentifier(resourceName, "drawable", context.getPackageName());
    }