Android Material Stepper 在导航回视图后显示空视图 [英] Android Material Stepper Showing Empty View After Navigating Back To The View

查看:26
本文介绍了Android Material Stepper 在导航回视图后显示空视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Android Material Stepper 库,它在片段中第一次初始化时运行良好,但是当我回到片段时,它显示空视图可以但还是一样的回应

i am using Android Material Stepper Library which is working fine for the first time initialization in fragment but when i come back to the fragment it is showing empty view i have tried everything tried to release stepper layout remove all views and everything else i could but still same response

  private void initStepper2() {
        Toast.makeText(getActivity(), "initStepper", Toast.LENGTH_SHORT).show();

        mStepperLayout = mainView.findViewById(R.id.stepperLayout);
        mStepperLayout.setSaveEnabled(false);


        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                stepArrayList.clear();
                stepArrayList.add(new FirstStepFragment());

                stepArrayList.add(new ThirdStepFragment());


                stepperAdapter = new StepperAdapter(getActivity().getSupportFragmentManager(), getActivity(), stepArrayList);
                mStepperLayout.setAdapter(stepperAdapter);

                mStepperLayout.requestLayout();
                mStepperLayout.refreshDrawableState();
                stepperAdapter.notifyDataSetChanged();
            }
        }, 300);
    }

这是我初始化步进器的地方

this is where i am initializing stepper

 @Override
    public void onDetach() {
        Toast.makeText(getActivity(), "OnDetach", Toast.LENGTH_SHORT).show();
//        mStepperLayout.removeAllViews();
//        mStepperLayout.removeAllViewsInLayout();
//        mStepperLayout.refreshDrawableState();
//        mStepperLayout.requestLayout();
//        mStepperLayout.setAdapter(null);

        super.onDetach();
    }

    @Override
    public void onDestroyView() {
        Toast.makeText(getActivity(), "onDestroyView", Toast.LENGTH_SHORT).show();
//        mStepperLayout.removeAllViews();
//        mStepperLayout.removeAllViewsInLayout();
//        mStepperLayout.refreshDrawableState();
//        mStepperLayout.requestLayout();
//        mStepperLayout.setAdapter(null);
        super.onDestroyView();

    }

    @Override
    public void onPause() {
        Toast.makeText(getActivity(), "onPause", Toast.LENGTH_SHORT).show();
//        mStepperLayout.removeAllViews();
//        mStepperLayout.removeAllViewsInLayout();
//        mStepperLayout.refreshDrawableState();
//        mStepperLayout.requestLayout();
//        mStepperLayout.setAdapter(null);
        super.onPause();
    }
    

我已经尝试了所有这些,但仍然没有得到它

i have tried all of these but still not getting it

这是我在初始化片段时第一次得到的

this is what i am getting for the first time when initializing fragment

这是我第二次重新导航到片段

and this is the second time when i re-navigate to the fragment

 mainView.findViewById(R.id.L1).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                navController = Navigation.findNavController(mainView);
                navController.navigate(R.id.action_newComplaintFragment_to_registerNCFragment);
            }
        });

这就是我通过导航地图使用 android x 导航控制器导航到片段的方式

this is how i am navigating to the fragment using android x navigation controller via navigation map

推荐答案

您在这里使用了错误的 FragmentManager:

You're using the wrong FragmentManager here:

stepperAdapter = new StepperAdapter(getActivity().getSupportFragmentManager(), getActivity(), stepArrayList);

当您的片段完全包含在另一个片段中时(例如您的 mStepperLayout 作为您的 NewComplainFragment 的一部分),您需要使用 childFragmentManager不是Activity的FragmentManager:

Whenever your fragment is fully container within another (such as your mStepperLayout being part of your NewComplainFragment), you need to use the childFragmentManager and not the Activity's FragmentManager:

stepperAdapter = new StepperAdapter(getChildFragmentManager(), getActivity(), stepArrayList);

这篇关于Android Material Stepper 在导航回视图后显示空视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆