shaking between images inside Java?

360 views Asked by At

So I have a ViewFlipper that links to a .xml file and when I shake it, it switches images, simple. I want it to switch images inside the java. how would I go about this? here is my main Java

package www.straightapp.com.shakerTest.html;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.ViewFlipper;

public  class ShakerTest extends Activity
implements Shaker.Callback {
private Shaker shaker=null;
ViewFlipper flipper;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    flipper=(ViewFlipper)findViewById(R.id.flipper);

    shaker=new Shaker(this, 1.25d, 500, this);
}

@Override
public void onDestroy() {
    super.onDestroy();
    shaker.close();
}

public void shakingStarted() {
    Log.d("ShakerDemo", "Shaking started!");
    flipper.showNext();
}

public void shakingStopped() {
    Log.d("ShakerDemo", "Shaking stopped!");

}
}

thanks -Chistian

3

There are 3 answers

0
Diego Torres Milano On

Your question is not very clear but I guess you want ViewFlipper.startFlipping() and ViewFlipper.stopFlipping().

1
sat On

you can get the ViewFlipper reference and use showNext() to flip to next child element.

1
TheCottonSilk On

You can have a look at ImageSwitcher class, here's its sample implementation. You can call its APIs based on shake.