ViewFlipper/ViewSwitcher 2nd View Empty
<p>I am a newbie to Android programming and now I want to create a ViewFlipper or ViewSwitcher for 2 views which will switch view between 1 and 2 columns. The problem is that the 1st view is ok, but when I use showNext() or showPrevious(), the 2nd view shows as blank, and I have been completely out of mind thinking what is wrong. I have tried ViewFlipper and ViewSwitcher with the same results.</p>

<p><strong>layout_devicelistmainswitcher.xml</strong></p>

<pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"&gt;


&lt;Button
    android:layout_width="70dp"
    android:layout_height="70dp"
    android:contentDescription="Grid/List View"
    android:id="@+id/viewbutton"
    android:background="@drawable/viewicon"
    android:layout_gravity="right" /&gt;

&lt;ViewFlipper
        android:id="@+id/vflipper"
        android:layout_width="match_parent"
        android:layout_height="match_parent"&gt;

        &lt;LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"&gt;

            &lt;GridView
                android:numColumns="1"
                android:gravity="center"
                android:columnWidth="100dp"
                android:stretchMode="columnWidth"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/grid"
                android:scrollbars="none" /&gt;
        &lt;/LinearLayout&gt;

        &lt;LinearLayout
            android:layout_width="200dp"
            android:layout_height="200dp"&gt;

            &lt;GridView
                android:numColumns="2"
                android:gravity="center"
                android:columnWidth="100dp"
                android:stretchMode="columnWidth"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/grid_l"
                android:scrollbars="none" /&gt;
        &lt;/LinearLayout&gt;

&lt;/ViewFlipper&gt;
</code></pre>

<p></p>

<p><strong>mainactivity.java</strong></p>

<pre><code>public class  activity_devicelist extends AppCompatActivity {

GridView grid;
Boolean viewtype = true;
ViewFlipper switcher;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_devicelistmainswitcher);

    Button button = (Button) findViewById(R.id.viewbutton);

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(activity_devicelist.this, "Button Clicked", Toast.LENGTH_SHORT).show();
            switcher = (ViewFlipper) findViewById(R.id.vflipper);
            switcher.showPrevious();
        }
    });
}
</code></pre>

<p>}</p>