Reputation: 3539
i have created a My custom listActivty by extending ListActivity like this.
public class MainList extends ListActivity {
ListView listView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
listView = getListView();
setContentView(R.layout.list_main);
}
}
And declaring its xml like this
<?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">
<ListView android:id="@id/android:list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</ListView>
<TextView android:id="@id/android:empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:text="My Text"
/>
</LinearLayout>
i am using CursorAdapter as listActivity adapter.Its showing perfectly with MainList is empty.
My problem is that i want to show more than a textview when MainList is empty. Basically i need custom view(imageview,button etc) to be shown when list is empty.How should i do this.
Thanks
Upvotes: 0
Views: 233
Reputation: 255
For the listview there is one default method to set empty view.
setEmptyView(view)
Try This.... In the place of view pass your custom view.
If you are not getting then tell me. I will post an example for this.
Upvotes: 1
Reputation: 7472
Try using the android:id/empty
for your custom view. I think you can apply the id to any view, not just a TextView
Upvotes: 0
Reputation: 7879
You may want to count the items in your CursorAdapter
. If 0 is returned, hide/show parts from your XML? That's how I done similar, but they may be better ways.
Upvotes: 0