gpt4 book ai didi

android - 如何将滑动选项卡 View 放入抽屉导航选项之一

转载 作者:行者123 更新时间:2023-11-29 01:37:14 24 4
gpt4 key购买 nike

更新代码:

@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
  • token “View”的语法错误,@expected
  • token “LayoutInflater”的语法错误,= 应在此 token 之后
  • token “ViewGroup”的语法错误,= 应在此 token 之后
  • 标记“Bundle”的语法错误,= 在此标记之后

最佳答案

在您的主页 fragment 中执行此操作

@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;
}

}

现在你可以这样称呼你 child 的家 fragment 了

您的 mainActivity 是母亲,然后您的主页 fragment 是您的 mainActivity 的 child 。在您的家庭 fragment 中托管 Reasturant 和 Map Fragment。请检查你如何使用dex2jar,如果你不能,我会把相关代码发给你

关于android - 如何将滑动选项卡 View 放入抽屉导航选项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27169093/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com