gpt4 book ai didi

java - Viewpager 内部的 Android Viewpager 不显示布局

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:12 29 4
gpt4 key购买 nike

我的任务是创建一个非常不正统的布局,只能通过另一个 viewpager 的第二个 Pane 内的 viewpager 来完成,幸运的是外部 viewpager 需要被锁定所以任务更现实一些,但是意外的问题出现在内部 viewpager 加载后 onCreateView 从未被调用的地方,我可以看到它左右滑动,因此内部 viewpager 已设置但由于某些奇怪的原因它不会加载任何内部 View ,任何帮助都会有很长的路要走谢谢

主要 Activity

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_fragment);

pagePosition = 0;

setupViews();

}

private void setupViews() {

//setup images to be changed later

ivCategory = (ImageView) findViewById(R.id.ivCatergory);
ivHome = (ImageView) findViewById(R.id.ivHome);
ivProfile = (ImageView) findViewById(R.id.ivProfile);

//setup the viewpager
pager = (CustomViewPager) findViewById(R.id.viewpager);

//add fragments to the fragment array
pageList.add(NavigationFragment.newInstance(0, getApplicationContext(), this));
pageList.add(NavigationFragment.newInstance(1, getApplicationContext(), this));
pageList.add(NavigationFragment.newInstance(0, getApplicationContext(), this));


// initialize the page adapter
pageAdapter = new FragmentHomeAdapter(getSupportFragmentManager(), pageList);

//set the page adapter to the viewpager
pager.setAdapter(pageAdapter);

//set homepage to be first
pager.setCurrentItem(1);


//disable swiping to mimic iphone behaviour
pager.setPagingEnabled(false);


}

浏览器

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

int pageType = getArguments().getInt(PAGE_TYPE);

View v;


if (pageType == 1) {//all inner fragments will happen here

v = inflater.inflate(R.layout.fragment_container, container, false);

//setup the inner viewpager
pager = (CustomViewPager) v.findViewById(R.id.viewpager);

pageList.add(HomeFragment.newInstance(0, context, getActivity()));
pageList.add(HomeFragment.newInstance(1, context, getActivity()));

// initialize the page adapter
pageAdapter = new FragmentHomeAdapter(getActivity().getSupportFragmentManager(), pageList);

//set the page adapter to the viewpager
pager.setAdapter(pageAdapter);

pager.setPagingEnabled(true);

}


return v;
}

内部 View 寻呼机

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

View v;

v = inflater.inflate(R.layout.fragment_list_feed, container, false);

lv = (ListView) v.findViewById(R.id.lvFeed);

listAdapter = new ListHomeAdapter(getArguments().getInt(PAGE_TYPE), feedListItems, getActivity());

//add header
header = (ViewGroup) inflater.inflate(R.layout.list_item_header, lv, false);
lv.addHeaderView(header, null, false);

lv.setAdapter(listAdapter);

if (getArguments().getInt(PAGE_TYPE) == 0) {

new getFeedListItems().execute();

} else {

new getFeedListItems().execute();

}

Toast.makeText(context, "This never shows",
Toast.LENGTH_SHORT).show();


return v;
}

最佳答案

在另一个 fragment 中显示 fragment 时,使用 getChildFragmentManager() 而不是 getSupportFragmentManager()

以这种方式初始化您的 pageAdapter:

pageAdapter = new FragmentHomeAdapter(getChildFragmentManager(), pageList);

关于java - Viewpager 内部的 Android Viewpager 不显示布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32747143/

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