我被嵌套的片段困住了,有人请指导我一点。我处于学习阶段...
实际上,我正在使用bottomNavigationView和popluate片段,并且在选择一项时,其中一个片段具有视图分页器和选项卡布局,并从火力基地加载列表数据。问题是,当选择其中包含viewpager的片段时,数据会成功获取,但不会在列表视图中填充,但是当我查看视图页面时,就会填充listview。任何人都可以帮助我解决这个问题,或指导我将网络呼叫分散放置在哪里或其他解决方案。
第一个具有Viewpager的片段。
public class explore extends Fragment {
public static explore Instance = null;
private TabLayout tabLayout;
private ViewPager viewPager;
private Activity activity;
private Context context;
private PagerAdapter pagerAdapter;
public static explore getInstance() {
if (Instance == null) {
Instance = new explore();
}
return Instance;
}
public explore() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
activity = (Activity) getActivity();
context = getActivity();
return inflater.inflate(R.layout.fragment_explore, container, false);
}
@Override
public void onViewCreated(@NonNull View v, @Nullable Bundle savedInstanceState) {
tabLayout = v.findViewById(R.id.tabs_Explore);
viewPager = v.findViewById(R.id.viewpager_Explore);
tabLayout.setupWithViewPager(viewPager);
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
List<Category> categories = new FirebaseHelper(getActivity()).getCategoriesList();
pagerAdapter = new PagerAdapter(getChildFragmentManager(), categories);
viewPager.setAdapter(pagerAdapter);
super.onActivityCreated(savedInstanceState);
}
}
寻呼机的第一个片段是(ChildFragment)
public class categories extends Fragment {
private static categories Obj = null;
private RecyclerView listView;
private List<Category> categoryList;
private CategoryAdapter categoryAdapter;
public categories() {
categoryList = new ArrayList<>();
}
public static categories getInstance() {
if (Obj == null) {
Obj = new categories();
}
return Obj;
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_blank, container, false);
listView = v.findViewById(R.id.mRecycler);
listView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
listView.setHasFixedSize(true);
SnapHelper helper = new LinearSnapHelper();
helper.attachToRecyclerView(listView);
categoryAdapter = new CategoryAdapter(getActivity(), categoryList);
listView.setAdapter(categoryAdapter);
return v;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
Bundle bundle = getArguments();
if (bundle != null) {
categoryList = bundle.getParcelableArrayList("data");
categoryAdapter.notifyDataSetChanged();
}
super.onActivityCreated(savedInstanceState);
}
}