0

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);
    }
TeeKay
  • 1,025
  • 2
  • 22
  • 60

3 Answers3

1

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" />
Damian Kozlak
  • 7,065
  • 10
  • 45
  • 51
0

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.

Iulian
  • 1,156
  • 11
  • 19
0

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.

user2145673
  • 363
  • 1
  • 9
  • 23
  • You need to start eliminating to better understand where is the issue, try to create a new simple layout and see if your code works fine, if it is and all conditions are met than the issue might be located in the way the view is arranged, if still doesnt work I would check the code again and using Log statements checks that all conditions are met. its a little bit more work but this way you can find your mistakes – user2145673 Jan 05 '16 at 21:37