tags:

views:

140

answers:

1

hi, i am developing an android app i need to go from one activity to another in that first i need to change the colors of button then a delay (so that the) and then call this same function(the one i am in rite now)

in objective-c it is done with [self performSelector:foo afterDelay:2]

so i need to the its java equivalent.

+3  A: 

For delayed actions in Android I'd recommend using the Android Handler class with its postDelayed() method.

Create a handler for your Activity as a member variable:

private Handler mHandler = new Handler(); 

And then add your delay action as follows:

mHandler.postDelayed(new Runnable() { 
        public void run() { 
            //Do you thing here
        } 
    },2000);
Dave Webb
Note that you don't necessarily need a Handler for this if you do not already have one. `postDelayed()` is also available on any widget (e.g., `Button`).
CommonsWare