setBackgroundResource不设置图像 [英] setBackgroundResource doesn't set the image
本文介绍了setBackgroundResource不设置图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Handler hnd = new Handler() {
@Override
public void handleMessage(Message msg) {
int id = sequence.get(msg.arg1);
if(msg.arg1 % 2 == 0) {
sq.get(id-1).setBackgroundResource(R.drawable.square_show);
} else {
sq.get(id-1).setBackgroundResource(R.drawable.square);
}
}
};
@Override
public void onResume() {
super.onResume();
Thread background = new Thread(new Runnable() {
public void run() {
try {
for(int i = 0; i < sequence.size()-1; i++) {
record_tv.setText(""+i);
Thread.sleep(200);
Message msg = hnd.obtainMessage();
msg.arg1 = i;
msg.sendToTarget();
}
} catch(Throwable t) {
}
}
});
background.start();
}
[code增订]现在它经过第一循环并停止
[CODE UPDATED] now it goes through the first loop and stops
你有什么想法,为什么code在第一runOnUiThread被执行,但它并没有做什么,我想要什么?
do you have any idea why the code in the first runOnUiThread gets executed but it doesn't do what i want?
我想是:改变形象,以广场,等待2秒,改变形象,以square_show,等待2秒,重复循环
what i want is: change the image to "square", wait 2 seconds, change the image to "square_show", wait 2 secs and repeat the loop
我一直在挣扎了一个小时,现在...
i've been struggling for an hour now...
推荐答案
您可以轻松地使用下面的code设置的图像。
You can easily set image using following code.
sq.get(id-1).setImageResource(R.drawable.square_show);
sq.get(id-1).setImageResource(R.drawable.square);
这篇关于setBackgroundResource不设置图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文