How to make the TextView invisible when there are items in listView?

Posted by Raphael Thomas Liewl on Stack Overflow See other posts from Stack Overflow or by Raphael Thomas Liewl
Published on 2012-12-07T05:00:10Z Indexed on 2012/12/07 5:03 UTC
Read the original article Hit count: 203

Filed under:
|
|

I like to display textView when there are no items in the listView whereas the textView will not display when there are items in the listView. My problem is even there are items in the listView, the textView still will be displayed in a short time and then load the items into listView. So, how to make the TextView invisible when there are items in listView?

Here is the codes:

 public void onCreate(Bundle savedInstancesState){
    super.onCreate(savedInstancesState);
    setContentView(R.layout.list_screen);
    user = getIntent().getExtras().getString("user");
    Log.d("dg",user);
    getList();
    lv = (ListView) findViewById(android.R.id.list);
    emptyText = (TextView)findViewById(android.R.id.empty);
    lv.setEmptyView(emptyText);       
}

list_screen.xml

 <?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"
  >

<ListView android:id="@+id/android:list"
      android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>

<TextView   android:id="@+id/android:empty"
            android:layout_width="fill_parent" 
            android:layout_height="fill_parent"
            android:text="@string/no_friend"
            android:gravity="center_vertical|center_horizontal"/>

</LinearLayout>

© Stack Overflow or respective owner

Related posts about android

Related posts about listview