How to programmatically add view in ViewFlipper
- by barmaleikin
Hi,
I have following main layout:
<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">
    <ViewFlipper android:id="@+id/viewstack" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent">
        <!-- Here I want to add my views which are located in separated xml files. -->
        </ViewFlipper>
</LinearLayout>
Here is example of my view:
view_url.xml
    
    
view_text.xml
<EditText android:text="@+id/EditText01" 
    android:id="@+id/EditText01" 
    android:layout_height="wrap_content" 
    android:contentDescription="Enter your text here" 
    android:layout_width="fill_parent" 
    android:height="200dp"/>
I am trying to add views:
viewstack = (ViewFlipper) findViewById(R.id.viewstack);));
View viewText = (View) findViewById(R.layout.view_text);
viewstack.addView(viewText); < -- Emulator is crashing at this line
View viewUrl = (View) findViewById(R.layout.view_url);
viewstack.addView(viewUrl);
I dont have any idea what is wrong with my code. I decided to put all my views in one file, but I still want to know how to fix my initial code.