How to programmatically add view in ViewFlipper

Posted by barmaleikin on Stack Overflow See other posts from Stack Overflow or by barmaleikin
Published on 2010-05-03T15:51:49Z Indexed on 2010/05/03 15:58 UTC
Read the original article Hit count: 585

Filed under:
|

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.

© Stack Overflow or respective owner

Related posts about android

Related posts about viewflipper