如何将滑动选项卡视图放在导航抽屉选项中

时间:2014-11-27 11:04:23

标签: android android-fragments tabs navigation

更新的代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_home, container, false);
    viewPager = (ViewPager)view.findViewById(R.id.base_pager);
    FragmentManager manager = getChildFragmentManager();
    viewPager.setAdapter(new MyFragmentPagerAdapter(manager));  
    return rootView;
}




class HomeFragment extends FragmentPagerAdapter {

    public HomeFragment(FragmentManager fm) {
        super(fm);
        // TODO Auto-generated constructor stub
    }

    @Override
    public android.support.v4.app.Fragment getItem(int item) {
        // TODO Auto-generated method stub
        android.support.v4.app.Fragment fragment = null;
        if (item == 0) {
            //MapFragment.message("Map");
            fragment = new MapFragment();
        } else if (item == 1) {
            //SavedLocationsFragment.message("locations");
            fragment = new MapFragment();
        } /*else if (item == 2) {
        fragment = new FragmentC();
    }*/
        return fragment;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return 2;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        // TODO Auto-generated method stub
        String title = new String();
        if (position == 0) {
            title = "Map";
        } else if (position == 1) {
            title = "savedLocations";
        }
        return title;
    }

}

我在onCreateView方法上遇到错误;

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_home, container, false);
    viewPager = (ViewPager)view.findViewById(R.id.base_pager);
    FragmentManager manager = getChildFragmentManager();
    viewPager.setAdapter(new MyFragmentPagerAdapter(manager));  
    return rootView;
}

错误是;

  • 此位置不允许使用注释@Override
  • 令牌上的语法错误"查看",@预期
  • 令牌上的语法错误" LayoutInflater",=此令牌后的预期
  • 令牌上的语法错误" ViewGroup",=此令牌后的预期
  • 令牌上的语法错误"捆绑",=此令牌后的预期

1 个答案:

答案 0 :(得分:1)

在您的家庭片段中执行此操作

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
        Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    View view = inflater.inflate(R.layout.fragment_activity, container, false);
    viewPager = (ViewPager)view.findViewById(R.id.base_pager);
    FragmentManager manager = getChildFragmentManager();
    viewPager.setAdapter(new MyFragmentPagerAdapter(manager));      
    return view;
}




class MyFragmentPagerAdapter extends FragmentPagerAdapter {

public MyFragmentPagerAdapter(FragmentManager fm) {
    super(fm);
    // TODO Auto-generated constructor stub
}

@Override
public android.support.v4.app.Fragment getItem(int item) {
    // TODO Auto-generated method stub
    android.support.v4.app.Fragment fragment = null;
    if (item == 0) {

        fragment = new PhotoCommnFragment();
    } else if (item == 1) {

        fragment = new ShowRestaurant();
    } /*else if (item == 2) {
        fragment = new FragmentC();
    }*/
    return fragment;
}

@Override
public int getCount() {
    // TODO Auto-generated method stub
    return 2;
}

@Override
public CharSequence getPageTitle(int position) {
    // TODO Auto-generated method stub
    String title = new String();
    if (position == 0) {
        title = "Map";
    } else if (position == 1) {
        title = "Restaurant";
    } else if (position == 2) {
        title = "Table 2";
    }
    return title;
}

}

现在你可以通过它来调用你孩子的家庭片段,就像这样

你的mainActivity是母亲然后你的家庭片段是你的mainActivity的孩子。 在你的家庭片段中托管Reasturant和Map Fragment。 亲切地检查你如何dex2jar,如果你不能给你发送相关代码