我試圖爲我的應用程序創建HighscoreList。 此列表基於SQL數據庫。保存名稱和分數工作得很好。 ListView控件是基於該行的XML文件:如何更改ListView中設置爲SimpleCursorAdapter的ImageView資源
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="4dip"
android:paddingBottom="6dip"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView android:id="@+id/NAME_CELL"
android:layout_width="250dip"
android:layout_height="wrap_content"
android:textSize="20dip" />
<TextView android:id="@+id/SCORE_CELL"
android:layout_width="20dip"
android:layout_height="wrap_content"
android:textSize="20dip" />
<ImageView android:id="@+id/PICTURE_CELL"
android:layout_width="50dip"
android:layout_height="20dip"
android:src="@drawable/no_picture" />
而且我想,對於例如,如果玩家達到分數的10 PICTURE_CELL ImageView的應顯示圖像。 現在我有一個光標它是通過數據庫會和找榜:
public void drawPictures()
{
if (dbCursor.moveToFirst()) {
do
{
if(dbCursor.getInt(2)<=4)
{
Log.d(TAG, "no picture");
}
else if((dbCursor.getInt(2) > 4) && (dbCursor.getInt(2) <= 9))
{
Log.d(TAG, "picture1");
}
else if((dbCursor.getInt(2) > 9) && (dbCursor.getInt(2) <= 19))
{
Log.d(TAG, "picture2");
}
else if(dbCursor.getInt(2) > 20)
{
Log.d(TAG, "picture3");
}
}
while (dbCursor.moveToNext());
但我不知道我怎樣才能改變各行中的每個的ImageView的資源。 請幫助我,這是殺了我好幾天!
謝謝!
你應該避免像 「dbCursor.getInt(2)」 這個消息不是很好的做法。而不是兩個,你應該有一個字符串常量,我從數據庫幫助程序公開的標識行的字符串常量。 – JoxTraex 2012-01-11 16:23:33