动态更新ViewPager中的Fragment
2016-07-22 15:32
295 查看
http://stackoverflow.com/questions/7263291/viewpager-pageradapter-not-updating-the-view/8024557#8024557
There are several ways to achieve this.
The first option is easier, but bit more inefficient.
Override
your
this:
This way, when you call
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
in
instantiating a new view. Then instead of using
you can use
find the view you want to update.
The second approach is very flexible and high performant. Kudos to alvarolb for the original research.
注意使用POSITION_NONE方法的时候,会将所有的Fragment移除,然后重新加载进来。
http://stackoverflow.com/questions/10849552/update-viewpager-dynamically/10852046#10852046
There are several ways to achieve this.
The first option is easier, but bit more inefficient.
Override
getItemPositionin
your
PagerAdapterlike
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.
注意使用POSITION_NONE方法的时候,会将所有的Fragment移除,然后重新加载进来。
http://stackoverflow.com/questions/10849552/update-viewpager-dynamically/10852046#10852046
相关文章推荐
- Android SlidingMenu 使用详解
- Ubuntu命令行下MySQL数据导出与导入
- Activity基本介绍
- 下拉加载数据 模拟 小实例
- Spring BeanNameAutoProxyCreator 与 ProxyFactoryBean区别
- 让PHP7达到最高性能的几个Tips
- 修改Oracle10g的默认8080端口
- Codeforces Round #324 (Div. 2) (B排列组合)(C贪心)(D哥德巴赫猜想 数论+暴力)
- memcache搜索分页
- Android 接口使用
- Android studio修改包名
- 红帽6 RHCE&RHCS认证培训笔记(3)
- Filter体现职责链模式
- Qt之资源系统
- WebApplicationInitializer (spring 3.x.x以上版本)
- 原码、反码、补码
- Qt之资源系统
- 使用 logback + slf4j 进行日志记录
- Qt之资源系统
- jvm 监控