Reputation: 33
If I click the button it works normally but when pressing more than 1 button the image view hangs for seconds before changing
My Code:
My Code:
ArrayList<Integer> ids = null;
ids=new ArrayList<Integer>();
ids.add(R.drawable.comp2);
ids.add(R.drawable.comp3);
ids.add(R.drawable.comp4);
ids.add(R.drawable.comp5);
ids.add(R.drawable.comp6);
ids.add(R.drawable.comp7);
ids.add(R.drawable.comp8);
ids.add(R.drawable.comp9);
ids.add(R.drawable.comp10);
button a = (Button)findViewById(R.id.button);
public void onclick{
name()
}
int i =o;
public void name() {
new Thread(new Runnable() {
public void run() {
imageview.post(new Runnable() {
public void run() {
if(i<ids.size()) {
imageview.setImageResource(ids.get(i));
i++;
}else i=0;
}
});
}
}).start();
Upvotes: 0
Views: 57
Reputation: 1350
They way you are doing is of no good. You are creating one thread and inside that thread you are changing ImageView
src. I would suggest you to use transition.
You can define it in xml as well as in dynamically using code.
Upvotes: 1