設置ListView加載中,空數據,加載數據失敗三種狀態的顯示
設置listview加載中,空數據,加載數據失敗三種狀態的顯示。
A library for showing different types of layouts when a list view is empty. These layouts can be shown when,
- the list is loading
- the list has no item to display
- an error occured trying to load items
Loading animation is also supported.
Screenshots
Usage
- Import the library project into your workspace.
- Use the imported project as a library for your project.
-
In the
onCreateevent of your activity use the following code.mListAdapter.clear(); EmptyLayout emptyLayout = new EmptyLayout(this, getListView());
-
When you want to show the loading animation, use this code.
mListAdapter.clear(); emptyLayout.showLoading();
-
When you want to show any error, use this code.
mListAdapter.clear(); emptyLayout.showError();
-
When your list doesn't have any item to show, use this code.
mListAdapter.clear(); emptyLayout.showEmpty();
Thats all you have to do to use this library. You may want to customize its behavior though.
P.S. Make sure you always clear the list adapter before calling showEmpty, showLoading and showError. The list have to empty after all.
Customization
There are bunch of methods to let you customize this pattern. Use the methods like this.
emptyLayout.setLoadingMessage("Please wait..."); Some useful methods are given below
showEmptyshowLoadingshowErrorsetLoadingViewsetEmptyViewsetErrorViewsetLoadingAnimationsetErrorMessagesetLoadingMessagesetEmptyMessagesetEmptyViewButtonClickListenersetLoadingViewButtonClickListenersetErrorViewButtonClickListenersetShowEmptyButtonsetShowLoadingButtonsetShowErrorButton
and there is more...



