Skip to content

Instantly share code, notes, and snippets.

@iriina
Created August 29, 2013 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iriina/6384158 to your computer and use it in GitHub Desktop.
Save iriina/6384158 to your computer and use it in GitHub Desktop.
void checkEmpty() {
final Adapter adapter = getAdapter();
if (getEmptyView() != null) {
updateEmptyStatus((adapter == null) || adapter.isEmpty());
}
}
@SuppressLint("WrongCall")
private void updateEmptyStatus(boolean empty) {
if (empty) {
if (getEmptyView() != null) {
getEmptyView().setVisibility(View.VISIBLE);
setVisibility(View.GONE);
} else {
// If the caller just removed our empty view, make sure the list
// view is visible
setVisibility(View.VISIBLE);
}
// We are now GONE, so pending layouts will not be dispatched.
// Force one here to make sure that the state of the list matches
// the state of the adapter.
// if (mDataChanged) {
onLayout(false, getLeft(), getTop(), getRight(), getBottom());
// }
} else {
if (getEmptyView() != null)
getEmptyView().setVisibility(View.GONE);
setVisibility(View.VISIBLE);
}
}
private void onDataChanged() {
adapterDataCount = adapter.getCount();
int activeIndex;
if (adapterIndex < 0)
activeIndex = 0;
else
activeIndex = Math.min(adapterIndex, adapterDataCount - 1);
releaseViews();
if (adapterDataCount > 0)
setSelection(activeIndex);
checkEmpty();
refreshAllPages();
}
@sahib20
Copy link

sahib20 commented Dec 26, 2014

i apply your method but it is not working same it is throw exception junit.framework.AssertionFailedError: Invalid indexInAdapter: 2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment