在Dashboard Activity中,顶部有一个Fragment,其中包含3个片段作为视图分页器。在以下情况下,视图分页器变为空白且无响应(如第二张屏幕截图所示):
“选项卡的片段”的代码为:
public class MainActivityGraphViewPager extends Fragment {
public MainActivityGraphViewPager() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_main_activity_graph_pager, container, false);
ViewPager viewPager = v.findViewById(R.id.fgraph_pager);
TabLayout tabx = v.findViewById(R.id.tab_layout_dashboard);
tabx.setupWithViewPager(viewPager, true);
viewPager.setAdapter(new SectionPagerAdapterFeaturedgraphs(getActivity().getSupportFragmentManager()));
viewPager.setCurrentItem(1, false);
viewPager.setOffscreenPageLimit(3);
return v;
}
private class SectionPagerAdapterFeaturedgraphs extends FragmentPagerAdapter {
public SectionPagerAdapterFeaturedgraphs(FragmentManager supportFragmentManager) {
super(supportFragmentManager);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
return new ExpenseManagerPieChart();
case 1:
return new BudgetandFitness();
case 2:
return new ExpendsFragments();
default:
return null;
}
}
@Override
public int getCount() {
return 3;
}
}}
在Dashboard Activity的onCreate()中调用MainActivityGraphViewPager.class:
MainActivityGraphViewPager mainActivityGraphPager=new MainActivityGraphViewPager();
this.getSupportFragmentManager().beginTransaction().replace(R.id.graph_pagers, mainActivityGraphPager).commit();
消除这种无反应性的可能解决方案是什么?