0

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.

4

1 回答 1

0

使用 AnimationDrawable 是从多个图像创建动画的“官方”方式

http://developer.android.com/reference/android/graphics/drawable/AnimationDrawable.html http://developer.android.com/guide/topics/graphics/drawable-animation.html

于 2013-06-06T05:49:19.990 回答