安卓程序中的睡眠功能
2022-09-03 01:07:38
有一些问题让我的程序进入睡眠我试图做的是,当btnStart被按下冷杉随机设置图片到12个ImageButtons然后我希望它暂停5秒,然后将第一个ImageButton更改为另一张图片
我的代码看起来像这样,现在按下按钮时它会立即暂停...
btnStart.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Collections.shuffle(pic);
int time=1;
press=true;
pic.get(0).setImageDrawable(getResources().getDrawable(R.drawable.memgreen));
pic.get(1).setImageDrawable(getResources().getDrawable(R.drawable.memgreen));
pic.get(2).setImageDrawable(getResources().getDrawable(R.drawable.memred));
pic.get(3).setImageDrawable(getResources().getDrawable(R.drawable.memred));
pic.get(4).setImageDrawable(getResources().getDrawable(R.drawable.memblue));
pic.get(5).setImageDrawable(getResources().getDrawable(R.drawable.memblue));
pic.get(6).setImageDrawable(getResources().getDrawable(R.drawable.memwhite));
pic.get(7).setImageDrawable(getResources().getDrawable(R.drawable.memwhite));
pic.get(8).setImageDrawable(getResources().getDrawable(R.drawable.mempurple));
pic.get(9).setImageDrawable(getResources().getDrawable(R.drawable.mempurple));
pic.get(10).setImageDrawable(getResources().getDrawable(R.drawable.memyellow));
pic.get(11).setImageDrawable(getResources().getDrawable(R.drawable.memyellow));
try {
Thread.sleep(5000);
pic.get(0).setImageDrawable(getResources().getDrawable(R.drawable.coin));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});