数据变化自动通知ViewPager的适配器:Android AutoNotifyViewPager

jopen 10年前

Android AutoNotifyViewPager这个项目是ViewPager的升级版。当内容被改变时,会自动通知viewpager的适配器。

  • By default ViewPager's adapter should be notified using mAdapter.notifyDataSetChanged() if data get's changed after setting adapter to avoid IllegalStateException
  • It get's difficult to update your adapter when PagerAdapter is in other class, typically different *.java
  • Example :
    • In this app, ListView's adapter & ViewPager's adapter share's same content.
    • When scrolled down to bottom of the page in ListView, GetMoreData is triggered, fetched, parsed & updated to ListView's adapter.
    • Seems easy, but when the user clicks & navigates to ViewPager after triggered and before updated, you end up in IllegalStateException as the data got changed but not notified.
    • This can be avoided having complex eventListeners, instead simply use AutoNotifyViewPager
    </li> </ul>

    项目主页:http://www.open-open.com/lib/view/home/1404284137030