使用holoeverywhere滑块插件时如何从活动中获取当前可见的片段? [英] How to get currently visible fragment from activity when using holoeverywhere slider addon?

查看:69
本文介绍了使用holoeverywhere滑块插件时如何从活动中获取当前可见的片段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在 holoeverywhere 中执行这些操作:

I want to know how to perform these actions in holoeverywhere:

在结合使用滑台插件和Tabber时从活动中获取当前可见且活动的片段的引用。

Get reference to the currently visible and active fragment from the activity when using slider addon in combination with tabber.

从活动中获取对TabsTabsSwipeFragment的引用/ other片段并动态禁用/启用滑动。

Get reference to TabsTabsSwipeFragment from the activity/other fragments and dynamically disable/enable swiping.

推荐答案


结合使用滑台插件和Tabber时,活动中当前可见和活动的片段:

您可以为片段提供标签,如下所示:

You can provide a tag for a Fragment like this:

sliderMenu.add("tab2", Fragment2.class, SliderMenu.GREEN).setTag("mynavigation-2");

也可以使用以下方法获取当前页码:

Also you can get the current page number using:

sliderMenu.getCurrentPage();

您无法直接获取当前的Fragment,但是可以将这两种方法结合起来,找到一个通过 FragmentManager

You have no way of obtaining the current Fragment directly, but you can combine these two methods and find a Fragment via the FragmentManager:

getSupportFragmentManager().findFragmentByTag("mynavigation-" + sliderMenu.getCurrentPage());

获取对 TabsTabsSwipeFragment.java 从活动 /其他片段中删除,并动态禁用/启用滑动。
在您的代码中:

Get a reference to the TabsTabsSwipeFragment.java from the Activity/other Fragments and dynamically disable/enable swiping. In your code:

getSupportFragmentManager().findFragmentByTag("mynavigation-2").getChildFragmentManager().findFragmentById(tagFragmentId);

在您的活动中:

private int tagFragmentId;
public void setTagFragmentId(int i) {
    Log.i(TAG, "fetched setTagFragmentId: " + i);
    tagFragmentId= i;
}

在您的标签中Fragment(是的子元素TabsTabsSwipeFragment ):

In your tab Fragment (which is a child of TabsTabsSwipeFragment):

   public void onViewCreated(View view, Bundle savedInstanceState) 
        ((mainActivity) getSupportActivity()).setTagFragmentId(this
                .getId());
    }


参考: https://github.com/Prototik/HoloEverywhere/wiki/Addon:-Slider

这篇关于使用holoeverywhere滑块插件时如何从活动中获取当前可见的片段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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