Last active
January 6, 2018 23:37
-
-
Save keyboardr/5259888 to your computer and use it in GitHub Desktop.
Demonstrate how to use the empty view to show progress indication and handle empty state. Note: if using a normal Fragment, you should call ListView.setEmptyView() to assign the empty view to the ListView.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ContentListFragment extends ListFragment implements LoaderCallbacks<List<Content>>{ | |
@Override | |
public void onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){ | |
return inflater.inflate(R.layout.layout, container, false); | |
} | |
@Override | |
public void onViewCreated(View view, Bundle savedInstanceState){ | |
super.onViewCreated(view, savedInstanceState); | |
getLoaderManager().initLoader(0, null, this); | |
} | |
@Override | |
public void onLoadFinished(Loader<List<Content>> loader, List<Content> content){ | |
setListAdapter(new ContentListAdapter(content); | |
((ViewSwitcher) getView().findViewById(R.id.empty)).setDisplayedChild(1); | |
} | |
@Override | |
public Loader<List<Content>> onCreateLoader(int arg0, Bundle arg1) { | |
return new ContentLoader(getActivity()); | |
} | |
@Override | |
public void onLoaderReset(Loader<List<Episode>> arg0) { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" > | |
<ListView | |
android:id="@android:id/list" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content"> | |
</ListView> | |
<ViewSwitcher | |
android:id="@android:id/empty" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" > | |
<ProgressBar | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" /> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="@string/content_empty" /> | |
</ViewSwitcher> | |
</FrameLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment