Results 1 to 3 of 3
  1. #1
    James_Martin is offline Member
    Join Date
    Aug 2015
    Posts
    1
    Rep Power
    0

    Default ViewFlipper without button- automatically switches through the different images

    Java File Code

    Java Code:
    public class MainActivity extends Activity {
    
        int mFlipping = 0 ; // Initially flipping is off
        Button mButton ; // Reference to button available in the layout to start and stop the flipper
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            /** Click event handler for button */
            OnClickListener listener = new OnClickListener() {
    
                @Override
                public void onClick(View v) {
                    ViewFlipper flipper = (ViewFlipper) findViewById(R.id.flipper1);
    
                    if(mFlipping==0){
                        /** Start Flipping */
                        flipper.startFlipping();
                        mFlipping=1;
                        mButton.setText(R.string.str_btn_stop);
                    }
                    else{
                        /** Stop Flipping */
                        flipper.stopFlipping();                 
                        mFlipping=0;
                        mButton.setText(R.string.str_btn_start);
                    }
                }
            };
    
            /** Getting a reference to the button available in the resource */
            mButton = (Button) findViewById(R.id.btn);
    
            /** Setting click event listner for the button */
            mButton.setOnClickListener(listener);
    
    
        }
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            getMenuInflater().inflate(R.menu.activity_main, menu);
            return true;
        }
    }
    XML FIle

    Java Code:
     <ViewFlipper 
                android:id="@+id/flipper1"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:flipInterval="3000"
                android:inAnimation="@android:anim/slide_in_left"
                android:outAnimation="@android:anim/slide_out_right"
                android:layout_centerInParent="true"
    
                >
    
    
                <ImageView 
                    android:src="@drawable/img1"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="@string/str_img1"
                    android:layout_gravity="center_horizontal"
                    />
    
                <ImageView 
                    android:src="@drawable/img2"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="@string/str_img2"
                    android:layout_gravity="center_horizontal"
                    />
    
                <ImageView 
                    android:src="@drawable/img3"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="@string/str_img3"
                    android:layout_gravity="center_horizontal"
                    />
    
                <ImageView 
                    android:src="@drawable/img4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:contentDescription="@string/str_img4"
                    android:layout_gravity="center_horizontal"
                    />
    
                <ImageView 
                    android:src="@drawable/img5"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:contentDescription="@string/str_img5"
                    android:layout_gravity="center_horizontal"
                    />
    
            </ViewFlipper>      
    
    
    </RelativeLayout

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: ViewFlipper without button- automatically switches through the different images

    Moved to Android section.

    Do you have any comments or questions about the code you've posted?
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    5,114
    Rep Power
    12

    Default Re: ViewFlipper without button- automatically switches through the different images

    Sooo.... are you just sharing code, or do you have a question?

    edit: yay, ninja'd by Norm :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Replies: 5
    Last Post: 05-21-2012, 10:33 AM
  2. Using switches...
    By besweeet in forum New To Java
    Replies: 11
    Last Post: 03-04-2010, 04:48 PM
  3. help with switches
    By spots of fire in forum New To Java
    Replies: 1
    Last Post: 01-23-2010, 09:02 PM
  4. Help with switches
    By Daniel in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 08:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •