0

I need to detach the gmt_option_list_dst_off.xml and attach a new layout gmt_option_list_dst_on.xml in the <include>tag, when button is clicked.

Following is the xml file:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="6" >

    <include
        android:id="@+id/gmt_optionlist"
        android:layout_weight="5"
        layout="@layout/gmt_option_list_dst_off" />

    <Button
        android:id="@+id/dstbutton"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="DST Off" >
    </Button>

</LinearLayout>

Suggest me is this possible to attach a new layout to include tag at runtime.

I have gone through few post, and currently i am using

parentOfAllInGMT.addView(layoutInflater.inflate(R.layout.gmt_option_list_dst_on, parentOfAllInGMT, true), 0);

but this is not correct.

Gaurav Gupta
  • 4,586
  • 4
  • 39
  • 72
  • I suggest you should use something like this : http://stackoverflow.com/questions/8589880/how-can-i-change-included-xml-layout-to-another-layout-on-java-code – Harish Godara Aug 07 '13 at 08:22

2 Answers2

0

Try this, it should do the trick:

ViewStub stub = (ViewStub) findViewById(R.id. gmt_optionlist);
stub.inflate();

Hope this helps.

user2652394
  • 1,686
  • 1
  • 13
  • 15
0

use addView() and removeViewAt called on LineaerLayout that contains include tag

pskink
  • 23,874
  • 6
  • 66
  • 77