I have a ListFragment that returns a ListView. If there are no items in the list, I'd like to display an alternative TextView instead. Supposedly you can add a TextView android:id="@android:id/empty" element within the XML.
But...
Adding FrameLayout containing both the ListView and the TextView predictably gives me "FrameLayout cannot be cast to ListView".
I can't just add a TextView element either. "The markup in the document following the root element must be wellformed."
And I can't switch to View instead of ListView because, well, it would no longer be a list.
...how am I supposed to do this?
Code:
@Override
public View onCreateView ( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState ) {
adapter = new ArrayAdapter<Project> ( getActivity (), android.R.layout.simple_list_item_1 );
arrayList = ProjectManager.getProjectList ( getActivity () );
for ( Project p : arrayList ) {
if ( p.getStatus () == Project.ONGOING ) {
adapter.add ( p );
}
}
ListView listView = ( ListView ) inflater.inflate ( R.layout.list, container, false );
listView.setAdapter ( adapter );
return listView;
}
XML:
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" />