PagerAdapter中的isViewFromObject()方法有什么用?
来源:互联网 发布:windows7用什么软件 编辑:程序博客网 时间:2024/04/28 09:32
http://segmentfault.com/q/1010000000484617
PagerAdapter的一个方法是
public Object instantiateItem (ViewGroup container, int position)
Create the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from finishUpdate(ViewGroup).
Parameters
container The containing View in which the page will be shown.
position The page position to be instantiated.Returns
Returns an Object representing the new page. This does not need to be a View, but can be some other container of the page.
该方法声明了返回值不一定是view,可以是任意对象。要知道view的添加是在该方法内部,通过container来添加的,所以这个方法不一定要返回view。
而isViewFromObject方法是用来判断pager的一个view是否和instantiateItem方法返回的object有关联,如果有关联做什么呢?去看代码吧
ViewPager源码,你去看下addNewItem方法,会找到instantiateItem的使用方法,注意这里的mItems变量。然后你再搜索下isViewFromObject,会发现其被infoForChild方法调用,返回值是ItemInfo。再去看下ItemInfo的结构,其中有一个object对象,该值就是instantiateItem返回的。
也就是说,ViewPager里面用了一个mItems(ArrayList)来存储每个page的信息(ItemInfo),当界面要展示或者发生变化时,需要依据page的当前信息来调整,但此时只能通过view来查找,所以只能遍历mItems通过比较view和object来找到对应的ItemInfo。
说的有些乱,好好看源码就懂了!
- PagerAdapter中的isViewFromObject()方法有什么用?
- PagerAdapter中的isViewFromObject()方法有什么用?
- 安卓PagerAdapter中的isViewFromObject()方法有什么用?
- js中的escape方法有什么用?
- java的main方法中的字符串数组有什么用
- java中的静态方法有什么作用?
- java中的void有什么作用啊?构造方法与方法有什么区别呢?
- JAVA中的方法和构造方法有什么区别
- 博客中的rss有什么用?
- html中的span是什么意思,有什么用
- java中的private到底有什么用
- 标签中的data-属性有什么用
- html中的<label>标签有什么用?
- Java中的@Override有什么用
- Vector类中的get和elementAt方法有什么区别
- 请问基类中的虚方法到底有什么作用?
- 汽车销售过程中的支付方法有什么特点
- 蒙特卡洛方法到底有什么用
- 从本地 上传 到 虚拟机
- 自学-001-Qt下载安装-Ubuntu
- php curl带有csrf-token验证模拟提交方法
- Kubernetes如何使用kube-dns实现服务发现
- FTL(Flash translation layer)闪存转换层
- PagerAdapter中的isViewFromObject()方法有什么用?
- JavaScript笔记:行为委托
- GIT报错:connect to host github.com port 22: Connection timed out
- Javascript函数节流
- 链表插入排序 lintcode
- 解决首次启动程序白屏时间过长的问题(针对Android Studio Instant Run)
- 10.URIs, URLs, and URNs
- Java安全之数字签名
- 获取手机的唯一标识符