0

我希望用图像填充列表视图,这些可绘制名称存储在 sqlite 中......

有我的代码:

 setContentView(R.layout.proba);
    ListView ekipe_list = (ListView) findViewById (R.id.list);      
    Cursor cursor = baza.query("ekipe", null, null, null, null, null,
            "_id" + " ASC");  
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(
            this, 
            R.layout.ekipe_layout, 
            cursor, 
            new String[] {"ime_ekipe","image"}, 
            new int[] {R.id.ime_ekipe,R.id.image});
    ekipe_list.setAdapter(adapter);
    ekipe_list.setCacheColorHint(Color.TRANSPARENT);

我的数据库:

String sql = "CREATE TABLE IF NOT EXISTS ekipe (" +
                    "_id INTEGER PRIMARY KEY AUTOINCREMENT, " + 
                    "ime_ekipe TEXT, " +                                            
                    "image TEXT )";
    baza5.execSQL(sql);


    ContentValues values = new ContentValues();

    values.put("ime_ekipe", "Ukraine");             
    values.put("image", "ukraine"); //ukraine.png in my drawable folder
    baza5.insert("ekipe", null, values);

    values.put("ime_ekipe", "Great Britain");       
    values.put("image", "unitedkingdom"); //unitedkingdom.png in my drawable folder
    baza5.insert("ekipe", null, values);

我的布局:

<TextView
    android:id="@+id/ime_ekipe"
    android:layout_width="wrap_content"
    android:textColor="#0000ff"
   android:textSize="20dp"
    android:layout_height="wrap_content"/>  


<ImageView
            android:id="@+id/image"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:scaleType="fitCenter"
           />

这仅适用于文本字段,但不在图像视图中显示图像......

4

1 回答 1

0

使用 Resources.getIdentifier()。

int resID = getResources().getIdentifier("org.anddev.android.testproject:drawable/bug", null, null);
// or
int resID = getResources().getIdentifier("bug", "drawable", "org.anddev.android.testproject");

http://www.anddev.org/viewtopic.php?p=17846

于 2013-05-23T19:18:25.657 回答