I already have this coded and working, however I am just wondering if there is a better solution for this.
Here is my code which currently does work:
_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));
}
});
}
}
As you can see the 2 drawable names come from an SQLite database table.