有没有办法摆脱它的子片段之一ViewPager适配器? [英] Is there a way to get the ViewPager adapter from one of its child fragments?

查看:149
本文介绍了有没有办法摆脱它的子片段之一ViewPager适配器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从ListFragment我们可以称之为getListAdapter()从它的子片段中的一个访问列表的适配器。有没有从其子片段,类似getListAdapter()在ListFragment之一访问ViewPager适配器的简单和类原生的方式?

From a ListFragment we can call getListAdapter() to access the list's adapter from one of its child fragments. Is there a simple and class-native way to access the ViewPager adapter from one of its child fragments, similar to getListAdapter() in ListFragment?

如果没有的话,是正确的做法,包括它的子片段的每一个参考ViewPager适配器?

If there isn't, is the correct approach to include a reference to the ViewPager adapter on every one of its child fragments?

推荐答案

比方说你有保护MyPagerAdapter mAdopter; 类。

从子片段来实现这个目的。

From child fragment class do this

((YourParentClass)getActivity()).mAdopter.WHAT_EVER_YOU_WANT_THIS_FOR;

请注意:您可以根据自己的需要改变访问修饰符(受保护)

Note: you can change access modifier (protected) according to your need.

这篇关于有没有办法摆脱它的子片段之一ViewPager适配器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆