2

I have created an activity in which there is four button in center . i want that when i click on any of button then there should be open another Xml file in same. i don't want to move on another activity . i want to show on same Activity with new Xml. This new Xml hide previous one.

first xml is:-

<include  
android:id="@+id/header"
layout="@layout/header"
android:layout_alignParentTop="true">
</include>

<Button
style="@style/homePageBtnStyle"
android:id="@+id/howToUse"
android:layout_centerHorizontal="true"
android:layout_marginTop="110dp"
android:text="@string/howToUse"
 />

<Button
style="@style/homePageBtnStyle"
android:id="@+id/purposeOfApp"
android:layout_alignLeft="@+id/howToUse"
android:layout_marginTop="10dp"
android:text="@string/purposeOfApp"
android:layout_below="@+id/howToUse"
/>

 <Button
style="@style/homePageBtnStyle"
android:id="@+id/rateThisApp"
android:layout_alignLeft="@+id/purposeOfApp"
android:layout_marginTop="10dp"
android:text="@string/rateThisApp"
android:layout_below="@+id/purposeOfApp"
/>

and second xml is:-

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:text="@string/howtousetext"
android:id="@+id/textInstruction"
android:textColor="@color/btn_border"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:
android:background="@color/themeColor"

/>
mega6382
  • 9,211
  • 17
  • 48
  • 69
Nitesh Kabra
  • 509
  • 2
  • 9
  • 17

3 Answers3

4

Best thing you can do is to use ViewFlipper. You can include multiple layouts in a single ViewFlipper and you can navigate from one layout to another using showNext() and showPrevious(). And since you have only two view, this becomes very simple.

rahul
  • 6,447
  • 3
  • 31
  • 42
1

call setContentView with the second xml id again and call invalidate().

C.d.
  • 9,932
  • 6
  • 41
  • 51
0

try this one:

    Button button1 = (Button) this.findViewById(R.id.button1);
    button1.setOnClickListener(new OnClickListener(){

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Test1Activity.this.setContentView(R.layout.main2);
        }});
zetsin
  • 303
  • 1
  • 4