Search code examples
androidlayoutviewviewflipper

viewflipper with different views


I want to build circle of three View,On each view two buttons to prev and next View all the three View connected by them. I have three layout for each View, and three CustomView that inflate accordingly with the layout. and above all one Activity that hold ViewFlipper.

my questions is:

1.how could I flip between them with viewFlipper?
with myFlipper.addView(myView) or should i use tag inside the viewFlipper layout?

2.how to inflate my view with the relevant Layout I already try LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); inflater.inflate(R.layout.t1, null);

my activity looks like this

public class Activity1 extends Activity {
   private ViewFlipper flipper;

   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.view_fliper_layout);
     flipper = (ViewFlipper) findViewById(R.id.flipper);
     myView1 temp1= new myView1 (this); 

     flipper.addView(myView1 , 1);     
     flipper.setDisplayedChild(1);
     }
 }

Solution

  • ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper);
    
    //Inflate the Views
    LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View v1 = inflater.inflate(R.layout.t1, null);
    View v2 = inflater.inflate(R.layout.t2, null);
    View v3 = inflater.inflate(R.layout.t3, null);
    
    //Add the views to the flipper
    viewFlipper.addView(v1);
    viewFlipper.addView(v2);
    viewFlipper.addView(v3);
    
    //Move between them
    flipper.showNext();
    flipper.showPrevious();
    

    http://developer.android.com/reference/android/widget/ViewAnimator.html#showNext()