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>
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.
use setVisibility method. for hiding button you can use button. setVisibility(View. GONE);.. you can use View.
<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);
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With