Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android layout with visibility GONE

Four views are using same xml. I want to show a linear layout for view 1 only. I put android:visibility="gone" in xml. And then I am doing the following for view 1-

LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone);  layone.setVisibility(View.VISIBLE); 

But that doesn't set the visibility to visible.

Isn't it possible to show the view once its declared GONE in xml ?

I don't want to converse the logic by just doing,

layone.setVisibility(View.GONE); 

in each of the three views except view 1.

Ideas or comments?

UPDATE:

My xml -

<TextView                 android:id="@+id/layone"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="Previous Page"                 android:textColor="#000000"                 android:textSize="16dp"                 android:paddingLeft="10dp"                 android:layout_marginTop="10dp"                 android:visibility="gone" />          <LinearLayout             android:layout_width="fill_parent"             android:layout_height="50dp"             android:orientation="horizontal"             android:padding="10dp"             android:gravity="center_vertical"             android:layout_marginLeft="10dp"             android:layout_marginRight="10dp"                       android:tag="PrevEntries"                  android:id="@+id/laytwo"             android:layout_marginTop="10dp"             android:background="@layout/roundedtext"             android:visibility="gone" >              <TextView                 android:id="@+id/laythree"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:layout_weight="1"                 android:text="Previous Page"                 android:textColor="#000000"                 android:textSize="18dp"                 android:gravity="center"                 android:textStyle="bold" />          </LinearLayout> 
like image 216
My God Avatar asked Apr 23 '13 09:04

My God


People also ask

What is visibility gone in Android?

When a View is gone, it means it doesn't take any space in the layout. When it is invisible, it will take the necessary room in a layout but you just don't see it.

How do you make a view visible and invisible on Android?

use setVisibility method. for hiding button you can use button. setVisibility(View. GONE);.. you can use View.


2 Answers

<TextView                 android:id="@+id/layone"                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:text="Previous Page"                 android:textColor="#000000"                 android:textSize="16dp"                 android:paddingLeft="10dp"                 android:layout_marginTop="10dp"                 android:visibility="gone" /> 

layone is a TextView.
You got your id wrong.

LinearLayout layone= (LinearLayout) view.findViewById(R.id.laytwo);// change id here  layone.setVisibility(View.VISIBLE); 

should do the job.

or change like this to show the TextView:

TextView layone= (TextView) view.findViewById(R.id.layone);      layone.setVisibility(View.VISIBLE); 
like image 122
Lazy Ninja Avatar answered Sep 23 '22 09:09

Lazy Ninja


Done by having it like that:

view = inflater.inflate(R.layout.entry_detail, container, false); TextView tp1= (TextView) view.findViewById(R.id.tp1); LinearLayout layone= (LinearLayout) view.findViewById(R.id.layone); tp1.setVisibility(View.VISIBLE); layone.setVisibility(View.VISIBLE); 
like image 29
My God Avatar answered Sep 21 '22 09:09

My God