Reputation: 73
i use this code for change ImageButton
image , but it not change at real-time.
it change one time only , not ImageButton
by ImageButton
.
for(int i = 1 ; i <= left_num ; i++ ){
int resourceId = this.getResources().getIdentifier("c"+i+"_r"+right_num, "id", this.getPackageName());
ImageButton imageButton = (ImageButton) findViewById(resourceId);
imageButton.setBackgroundResource(R.drawable.white_circle);
sleep(500);
}
Upvotes: 0
Views: 109
Reputation: 5308
It probably changes "in real-time", but you're not able to see it because the line of code sleep(500)
is ignored and does not do what you expect it to do.
Edit:
You can set a Timer to update the ImageButtons sequentially by calling the method below:
private void updateImageButtonsSequentially() {
int iteration = 0;
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
int resourceId = this.getResources().getIdentifier("c"+iteration+"_r"+right_num, "id", this.getPackageName());
iteration++;
ImageButton imageButton = (ImageButton) findViewById(resourceId);
imageButton.setBackgroundResource(R.drawable.white_circle);
}
},0,500);
}
Upvotes: 1