1

Please help me fix it :

http://s27.postimg.org/bp1txpnoj/Capture.png

xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:id="@+id/LinearLayout2"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:orientation="vertical"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context=".Main_Page" >

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="16dp"
    tools:listitem="@android:layout/simple_spinner_dropdown_item" />

</LinearLayout>

this is the main.xml code of my app. The code has been changed from Relative to LinearLayout

1 Answers1

0

Use LayoutInflator and inflate views to your main view when different values in the spinner are chosen.

//Main Layout

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/main_layout_id">

<Spinner
    android:id="@+id/spinner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_centerHorizontal="true"
    android:layout_marginBottom="16dp"
    tools:listitem="@android:layout/simple_spinner_dropdown_item" />

<LinearLayout 
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/insert_Layout">
</LinearLayout>

</LinearLayout>

//Layout 2

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:layout_width="fill_parent"
              android:layout_height="fill_parent"
              android:id="@+id/layout_item_id">

    <TextView android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:text="Hello, this is the inflated text :D"
              android:layout_gravity="center"
              android:gravity="center_horizontal"
              android:id="@+id/text_item_id"/>
</LinearLayout>

//call the main layout from xml

linearLayout inset_layout= (LinearLayout)findViewById(R.id.insert_Layout);

/create a view to inflate the layout_item (the xml with the textView created before)

View view = getLayoutInflater().inflate(R.layout.layout_item, mainLayout,false);

//add to the mail layout

mainLayout.addView(view);

Hope this helps :)

Sujay
  • 396
  • 1
  • 4
  • 9
  • Yes, the code dynamically inflates layout 2 in the main layout.You can have many place holders in your main layout and inflate different layouts accordingly. http://developer.android.com/reference/android/view/LayoutInflater.html – Sujay Nov 29 '13 at 05:54
  • thx dude if u dont mind can u help me with this one to (http://stackoverflow.com/q/20280272/3026643) – Noha Philip Nov 29 '13 at 07:16