Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Made an example for you that shows howto display different views in a ViewFlipper.</p> <p>The layout of the example is made up of the following parts. There are three radio buttons. A ViewFlipper is placed below the radio buttons. This flipper holds three different simple views with different texts.</p> <p>The radio buttons are then hooked up to a listener in the java code that will change the view displayed by the ViewFlipper depending on which radio button that currently is chosen.</p> <p><strong>XML</strong></p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;LinearLayout android:id="@+id/LinearLayout01" android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical"&gt; &lt;RadioGroup android:id="@+id/radioGroup1" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;RadioButton android:layout_height="wrap_content" android:id="@+id/radio0" android:layout_width="wrap_content" android:text="Show View 1" android:checked="true"&gt;&lt;/RadioButton&gt; &lt;RadioButton android:layout_height="wrap_content" android:id="@+id/radio1" android:layout_width="wrap_content" android:text="Show view 2"&gt;&lt;/RadioButton&gt; &lt;RadioButton android:layout_height="wrap_content" android:id="@+id/radio2" android:layout_width="wrap_content" android:text="Show View 3"&gt;&lt;/RadioButton&gt; &lt;/RadioGroup&gt; &lt;ViewFlipper android:id="@+id/ViewFlipper01" android:layout_width="wrap_content" android:layout_height="wrap_content"&gt; &lt;!--adding views to ViewFlipper--&gt; &lt;TextView android:id="@+id/TextView01" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First view is now displayed"&gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/TextView02" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second view is now displayed"&gt;&lt;/TextView&gt; &lt;TextView android:id="@+id/TextView03" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Third view is now displayed"&gt;&lt;/TextView&gt; &lt;/ViewFlipper&gt; &lt;/LinearLayout&gt; </code></pre> <p><strong>JAVA</strong></p> <pre><code>package com.test.threeviews; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.RadioButton; import android.widget.ViewFlipper; public class ThreeViewsinaFlipperActivity extends Activity { RadioButton RB0; RadioButton RB1; RadioButton RB2; ViewFlipper VF; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); /* * Find the views declared in main.xml. */ RB0 = (RadioButton) findViewById(R.id.radio0); RB1 = (RadioButton) findViewById(R.id.radio1); RB2 = (RadioButton) findViewById(R.id.radio2); VF = (ViewFlipper) findViewById(R.id.ViewFlipper01); /* * Set a listener that will listen for clicks on the radio buttons and * perform suitable actions. */ RB0.setOnClickListener(radio_listener); RB1.setOnClickListener(radio_listener); RB2.setOnClickListener(radio_listener); } /* * Define a OnClickListener that will change which view that is displayed by * the ViewFlipper */ private OnClickListener radio_listener = new OnClickListener() { public void onClick(View v) { switch (v.getId()) { case R.id.radio0: VF.setDisplayedChild(0); break; case R.id.radio1: VF.setDisplayedChild(1); break; case R.id.radio2: VF.setDisplayedChild(2); break; } } }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload