如何知道哪些卡是活跃在onCreateView功能? [英] How to know which tab is active in onCreateView function?

查看:116
本文介绍了如何知道哪些卡是活跃在onCreateView功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能知道哪个选项卡是活跃在我的

How can I know that which tab is active in my

公开查看onCreateView(LayoutInflater充气器,容器的ViewGroup,捆绑savedInstanceState)函数???

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) function???

继code正在为刚刚拳头导航但此后,在每一个标签中,显示最近的布局。

Following code is working for just fist navigation but after that in every tab it show last layout.

public final class RobozoxFragment extends Fragment {
private static final String KEY_CONTENT = "RobozoxFragment:Content";
private static int currentPosition = 100;
public static RobozoxFragment newInstance(String content,int position) {
    currentPosition = position;
    RobozoxFragment fragment = new RobozoxFragment();
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < 20; i++) {
        builder.append(content).append(" ");
    }
    builder.deleteCharAt(builder.length() - 1);
    fragment.mContent = builder.toString();
    return fragment;
}
@Override

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View myFragmentView;

    if(currentPosition == 1){
        myFragmentView = inflater.inflate(R.layout.first, container, false);
    }else if(currentPosition == 2){
        myFragmentView = inflater.inflate(R.layout.second, container, false);
    }else if(currentPosition == 3){

        myFragmentView = inflater.inflate(R.layout.third, container, false);
    }else if(currentPosition == 4){
        myFragmentView = inflater.inflate(R.layout.fourth, container, false);
    }else if(currentPosition ==5){
        myFragmentView = inflater.inflate(R.layout.fifth, container, false);
    }else{
        myFragmentView = inflater.inflate(R.layout.activity_main, container, false);
    }
    return myFragmentView;
}

我认为问题出在 onCreateView 函数,其中我无法获得活动标签的位置。

I think problem is in onCreateView function where I am unable to get the active tab location.

我怎样才能得到这个东西做的。??

How can i get this thing done.??

推荐答案

得到了解决:)
获取当前位置通过捆绑和传递参数。示例code以下。

Got the Solution :) Get the Current Position By Using Bundle and Passing Arguments. Sample Code Below..

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView;
    Bundle args = getArguments();
    int currentView = args.getInt(Constants.ARG_SECTION_NUMBER)-2;

    if(currentView == 0){
        rootView = inflater.inflate(R.layout.lay1, container, false);
    }else if(currentView == 1){
        rootView = inflater.inflate(R.layout.lay2, container, false);
    }else {
        rootView = inflater.inflate(R.layout.activity_main, container, false);
    }

    return rootView;
}


@Override
public Fragment getItem(int i) {
    switch (i) {
    case 0:
        // The first section of the app is the most interesting -- it offers
        // a launchpad into the other demonstrations in this example
        // application.
        return new LaunchpadSectionFragment();

    default:
        // The other sections of the app are dummy placeholders.
        Fragment fragment = new RobozoxSectionFragment();
        Bundle args = new Bundle();
        args.putInt(Constants.ARG_SECTION_NUMBER, i + 1);
        fragment.setArguments(args);
        return fragment;
    }
}

这篇关于如何知道哪些卡是活跃在onCreateView功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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