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() {
L开发者_如何学Cog.d("ShakerDemo", "Shaking stopped!");
}
}
thanks -Chistian
Your question is not very clear but I guess you want ViewFlipper.startFlipping() and ViewFlipper.stopFlipping().
you can get the ViewFlipper reference and use showNext() to flip to next child element.
You can have a look at ImageSwitcher class, here's its sample implementation. You can call its APIs based on shake.
精彩评论