I have a the following code:
final ImageButton bgreen = (ImageButton) findViewById(R.id.imageButton1c);
bgreen.setImageResource(R.drawable.xgp);
gHandler.postDelayed(greenRunnable, delay); // this reverses the above two lines in a second
However, I have found that the image change DOES NOT actually occur until all other commands added before AND AFTER it are completed and then it has an empty queue and is waiting for an onclick listener. Why is this? Is there a better way? It ends up that this and undoing this happens sequentially even though I used a handler/runnable combo (which I believe is a completely different thread?) to delay the undoing.
Can I use a different method like:
ButtonName.setImageResource(R.drawable.ImageName);
that might perform better?
I need to do the clicking as a demonstration (ie without user interaction) and it is this part that is the problem. ie I can’t simply do this in XML, e.g.:
<item android:state_pressed="true"
android:drawable="@drawable/login_selected" /> <!-- pressed -->
This seems to be related to using the sleep command. Cleverly using Handler/Runnable combos helps here.