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 ?
Asked
Active
Viewed 108 times
1 Answers
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
-
Thank you for your quick response." In your layout have both button and textview in the same place" .How can i do this ? – Rage Aug 26 '13 at 10:30
-
I have edited my answer to add some code for you – Sushil Aug 26 '13 at 10:36