Well, i want to setting a button with setBackground(), but after this update i want to sleep the thread at 500 ms and after setting another background at the same button, all this inside a onTouch method.
Example
public boolean onTouch(View v,MotionEvent event){
switch(event.getAction()){
case MotionEvent.ACTION_UP:
button.setBackground(R.drawable.bckg1);
try{
Thread.sleep(500);
button.setBackground(R.drawable.bckg2);
}catch(Exception e){}
break;
}
You should not ever make the main (UI) thread sleep. The android threading model has two rules 1) dont block the main thread for more than about 5 seconds (or else you’ll get an App Not Responding crash) 2) dont manipulate the UI from off of the main thread. You’re trying to violate the first of those rules even if you’re only sleeping for 500.
Instead, use a handler and post a delayed runnable at 5000 millis and then inside the runnable, update the background of the button.