MarcoMix
MarcoMix

Reputation: 31

How to set a Delay on imageSwitcher image change (Android)

I'm working on a menu for my app that is made of a Gallery and sliding it I select a different background image.

 gallery.setOnItemSelectedListener(new Gallery.OnItemSelectedListener() {
   @Override
   public void onItemSelected(AdapterView<?> arg0, View arg1,
     int arg2, long arg3) {

    imageSwitcher.setImageResource(imm[arg2]);

The idea works decently but the sliding effect is not fluid. My idea is to set a delay, setting:

imageSwitcher.setImageResource(imm[arg2]);

only after a 200ms or so... is something like this possible?

Thank you :) Marco

Upvotes: 3

Views: 1091

Answers (1)

blessanm86
blessanm86

Reputation: 31779

You can use the Timer and TimerTask class to schedule a operation to happen every 200ms

Something like

Timer scrollTimer = new Timer();
scrollTimer.schedule(
    new TimerTask(){
    @Override
    public void run(){
        runOnUiThread(Call the method to do ur work);
    }
},
0,200);

Upvotes: 1

Related Questions