Reputation: 1065
I have a textview that should get visible if a particular condition is satisfied. The other views are functioning properly on satisfaction of the condition but the text view is not getting visible.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi "
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:paddingLeft="5dp"
android:id="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:id="@+id/name"
android:textStyle="bold"
android:layout_centerVertical="true"
android:text="!"
android:layout_toRightOf="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textStyle="italic"
android:textColor="#FFF"
android:id="@+id/edit"
android:paddingRight="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:text="Hello"
android:textColor="#000"
android:layout_below="@+id/drawerList"
android:layout_marginTop="15dp"
android:paddingLeft="5dp"
android:textStyle="italic"/>
</RelativeLayout>
Text view with id=hello is not showing up.
This is the code that I am using-
if(fname!="!")
{
edit.setText("EDIT");
hello.setVisibility(View.VISIBLE);
}
else
{
edit.setText("What's going on?");
hello.setVisibility(View.GONE);
}
Upvotes: 0
Views: 2331
Reputation: 7093
Change RecyclerView
and TextView
attributes - make RecyclerView
be layout_above
of your TextView
, not TextView
below RecyclerView
.
Also layout_alignParentBottom="true"
must be added to TextView
.
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_above="@+id/hello"
android:layout_marginTop="15dp" />
<TextView
android:id="@+id/hello"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:paddingLeft="5dp"
android:text="Hello"
android:layout_alignParentBottom="true"
android:textColor="#000"
android:textStyle="italic" />
Upvotes: 1
Reputation: 363
I loaded your xml to android studio and seems to be ok except that the textview with id "hello" seems to be pushed down in the layout by the recyclerview. try to load it as below and see if it helps:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFF">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentTop="true"
android:background="#000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hi "
android:textStyle="bold"
android:layout_centerVertical="true"
android:textColor="#FFF"
android:paddingLeft="5dp"
android:id="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:id="@+id/name"
android:textStyle="bold"
android:layout_centerVertical="true"
android:text="!"
android:layout_toRightOf="@+id/hi"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:textStyle="italic"
android:textColor="#FFF"
android:id="@+id/edit"
android:paddingRight="5dp"
android:layout_alignParentRight="true"/>
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_above="@+id/hello" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/hello"
android:text="Hello"
android:textColor="#000"
android:paddingLeft="5dp"
android:textStyle="italic"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true" />
</RelativeLayout>
One more thing is regarding your condition, try to store your "!" in s variable and then do the comparison. also you using Log statement verify if your condition is met.
Upvotes: 0
Reputation: 1156
For the TextView add inside the declaration:
android:visibility="invisible"
and your code should be:
if(fname!="!")
{
edit.setText("EDIT");
hello.setVisibility(View.VISIBLE);
}
else
{
edit.setText("What's going on?");
hello.setVisibility(View.INVISIBLE);
}
Hope this solves your problem.
Upvotes: 0