Skip to content

Instantly share code, notes, and snippets.

@thanhit93
Created December 20, 2016 05:55
Show Gist options
  • Save thanhit93/03c502bf7342af5e7af87c746e0d27d1 to your computer and use it in GitHub Desktop.
Save thanhit93/03c502bf7342af5e7af87c746e0d27d1 to your computer and use it in GitHub Desktop.
http://stackoverflow.com/questions/7263291/viewpager-pageradapter-not-updating-the-view
There are several ways to achieve this.
The first option is easier, but bit more inefficient.
Override getItemPosition in your PagerAdapter like this:
public int getItemPosition(Object object) {
return POSITION_NONE;
}
This way, when you call notifyDataSetChanged(), the view pager will remove all views and reload them all. As so the reload effect is obtained.
The second option, suggested by Alvaro Luis Bustamante (previously alvarolb), is to setTag() method in instantiateItem() when instantiating a new view. Then instead of using notifyDataSetChanged(), you can use findViewWithTag() to find the view you want to update.
The second approach is very flexible and high performant. Kudos to alvarolb for the original research.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment