I’m trying to display a TextView on top of a ListView from within a ListActivity, but the text is not showing up.
LayoutInflater inflater = (LayoutInflater)getSystemService( Context.LAYOUT_INFLATER_SERVICE );
View layout = inflater.inflate( R.layout.main, null );
TextView myTextView = (TextView)layout.findViewById( R.id.myTextView );
myTextView.setVisibility( View.VISIBLE );
myTextView.setText( R.string.emptyList );
setContentView( layout );
Here is the main layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView android:id="@+id/myTextView"
android:paddingLeft="10dp"
android:paddingTop="10dp"
android:textSize="16sp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
I want an “Empty list” notice to go at the top of the screen in case the list view is empty.
Why dont you use setEmptyView for your ListView and do your notification that way.
And call in your code.
Check these for more info.
Correct use of setEmtpyView in AdapterView
http://www.technotalkative.com/android-listview-setemptyview/