我已经有了这个编码和工作,但我只是想知道是否有更好的解决方案。
这是我目前正常运作的代码:
_index = 1;
_timer = new Timer();
_timer.schedule(new TickClass(), 1000, 1000);
public class TickClass extends TimerTask
{
private int columnIndex;
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
if (_index == 1) {
columnIndex = cursor.getColumnIndex(MySQLiteHelper.COLUMN_IMAGE_2);
_index = 2;
}
else {
columnIndex = cursor.getColumnIndex(MySQLiteHelper.COLUMN_IMAGE_1);
_index = 1;
}
String image_1 = cursor.getString(columnIndex);
image_1 = image_1.replace(".png", "");
int resourceId = getResources().getIdentifier(getPackageName() + ":drawable/" + image_1, null, null);
image_1_view.setImageDrawable(getResources().getDrawable(resourceId));
}
});
}
}
正如您所看到的,2个可绘制的名称来自SQLite数据库表。
答案 0 :(得分:0)