fragments in viewpager, no view found error

前端 未结 8 1179
面向向阳花
面向向阳花 2020-12-19 09:23

I have an activity holding a fragment, in this fragment there is a button , when it is clicked, a dialog is popped out.

In this dialog, there is a Viewpager, which

相关标签:
8条回答
  • 2020-12-19 10:22

    Try using DialogFragment and pass getChildFragmentManager() to your FragmentPagerAdapter's constructor.

    DialogFragment:

    public static class MyDialogFragment extends DialogFragment {
    
        private ViewPager viewPager;
        MySectionPagerAdapter mAdapter;
    
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.m_layout, container);
    
            viewPager = (ViewPager) view.findViewById(R.id.viewpager);
            mAdapter = new MySectionPagerAdapter(getChildFragmentManager());
            viewPager.setAdapter(mAdapter);
    
            return view;
        }
    
    
    }
    
    0 讨论(0)
  • 2020-12-19 10:25

    I found in Google a blog post, it says that viewpager doesn't work on Dialog. It also says we should use DialogFragment instead.

    Here is the link to that blog: http://www.intellicode.in/viewpager-inside-dialog/

    0 讨论(0)
提交回复
热议问题