0

At the certain part of screen, i sometimes need to display a button and sometimes a TextView. When the Button is visible, TextView is invisible and vice-versa.(at the same place). How can i do this ?

Rage
  • 191
  • 1
  • 3
  • 10

1 Answers1

0

This is very simple to achieve. In your layout have both button and textview in the same place. make one of them visibile and hide other one using android:visibility="visible"/android:visibility="gone"

form code you can hide and show accordingly them accordingly by using

View.setVisibility(View.VISIBLE) 
View.setVisibility(View.GONE)

Something like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:visibility="visible"
    />

<Button  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:visibility="gone"
    />

</RelativeLayout>
Sushil
  • 8,250
  • 3
  • 39
  • 71