So here is my problem:
I have here an edittext
, 2 textviews
and 2 listviews
. The functionality of this activity is a search activity. when you type a certain word or phrase, there can be a result in either in Tools or Articles. My main problem is, when both tools and articles cannot find that word, I want the one in the red box, be something like this:
but I don't know how. I tried hiding the listview
s but still I failed. So can you help me with this matter? Here is the xml
file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/navbar_search"
android:paddingLeft="5dp" >
<ImageView
android:id="@+id/buttonBack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/btn_back" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@color/violet"
android:padding="5dp" >
<EditText
android:id="@+id/editTextSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:hint="@string/hint_search"
android:paddingLeft="35dp" >
</EditText>
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/editTextSearch"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/search" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textArticlesResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/label_articles"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<ListView
android:id="@+id/listViewArticlesResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textArticlesResult"
android:cacheColorHint="@color/white"
android:scrollbars="none"
android:visibility="gone" >
</ListView>
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="@color/blue"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textToolsResult"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:text="@string/label_tools"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/black"
android:textStyle="bold" />
<ListView
android:id="@+id/listViewToolsResult"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/textToolsResult"
android:cacheColorHint="@color/white"
android:scrollbars="none" >
</ListView>
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="46dp" >
<ImageView
android:id="@+id/tabHome"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_home_unselected" />
<ImageView
android:id="@+id/tabFb"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_fb_unselected" />
<ImageView
android:id="@+id/tabSearch"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_search_selected" />
<ImageView
android:id="@+id/tabFaves"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_myfaves_unselected" />
<ImageView
android:id="@+id/tabSettings"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:contentDescription="@string/desc"
android:scaleType="fitXY"
android:src="@drawable/tab_settings_unselected" />
</LinearLayout>
</LinearLayout>
What I've done is to programatically hide the view. In my case, I wanted to hide the TextView when the content provider returned an empty string. Do this by:
TextView address = (TextView) findViewById(R.id.address);
address.setVisibility(View.GONE);
Don't forget to re-enable the TextView when you get a non-empty string by:
address.setVisibility(View.VISIBLE);
Note that View.INVISIBLE
will only make the TextView disappear. View.GONE
makes it so the TextView isn't even accounted for in the layout.