Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 将viewpager放入对话框错误“;getSupportFragmentManager();_Java_Android_Android Fragments_Dialog_Android Viewpager - Fatal编程技术网

Java 将viewpager放入对话框错误“;getSupportFragmentManager();

Java 将viewpager放入对话框错误“;getSupportFragmentManager();,java,android,android-fragments,dialog,android-viewpager,Java,Android,Android Fragments,Dialog,Android Viewpager,我试图在自定义对话框(wasabeef的blurdialogfragment)中放置一个viewpager,但我不知道问题出在哪里,也不知道如何替换它,因为它说:“无法解决方法getSupportFragmentManager() 如果有人能帮我,我将不胜感激 代码: 有人能帮忙吗?谢谢。取决于您从何处调用它,但我怀疑这是因为当getSupportFragmentManager是AppCompatActivity类上的一个方法时,您是从片段调用它的,我想这就是问题所在,但是,我如何解决它呢?关于

我试图在自定义对话框(wasabeef的blurdialogfragment)中放置一个viewpager,但我不知道问题出在哪里,也不知道如何替换它,因为它说:“无法解决方法getSupportFragmentManager()

如果有人能帮我,我将不胜感激

代码:


有人能帮忙吗?谢谢。

取决于您从何处调用它,但我怀疑这是因为当
getSupportFragmentManager
AppCompatActivity

类上的一个方法时,您是从片段调用它的,我想这就是问题所在,但是,我如何解决它呢?关于我更改的方法?@fluffyBatman它在SectionsPagerAdapter中告诉我无法应用getFragmentManager()
SectionsPagerAdapter
的构造函数采取了什么?@fluffyBatman
public SectionsPagerAdapter(FragmentManager fm){super(fm);}
这是构造函数
 public class DialogHelperForNoobs extends BlurDialogFragment {

    String personName;
    String personGivenName;
    String personFamilyName;
    String personEmail;
    String personId;


    private SectionsPagerAdapter mSectionsPagerAdapter;

    private ViewPager mViewPager;

    public DialogHelperForNoobs() {
    }

    @NonNull
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        return createDialogHelperForNoobs();
    }

    public AlertDialog createDialogHelperForNoobs() {

        Bundle mArgs = getArguments();

        //Datos Usuario
        personName = mArgs.getString("personName");
        personGivenName = mArgs.getString("personGivenName");
        personFamilyName = mArgs.getString("personFamilyName");
        personEmail = mArgs.getString("personEmail");
        personId = mArgs.getString("personId");

        //INFLADOR DIALOGO
        AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
        LayoutInflater inflater = getActivity().getLayoutInflater();
        View v = inflater.inflate(R.layout.activity_dialog_helper_for_noobs, null);

        //Error in FragmentManager getSupportFragmentManager()
        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        // Set up the ViewPager with the sections adapter.
        mViewPager = (ViewPager) v.findViewById(R.id.ViewPager);
        mViewPager.setAdapter(mSectionsPagerAdapter);

        builder.setView(v);




        return builder.create();
    }


    public static class PlaceholderFragment extends Fragment {
        /**
         * The fragment argument representing the section number for this
         * fragment.
         */
        private static final String ARG_SECTION_NUMBER = "section_number";

        public PlaceholderFragment() {
        }

        /**
         * Returns a new instance of this fragment for the given section
         * number.
         */
        public static PlaceholderFragment newInstance(int sectionNumber) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_SECTION_NUMBER, sectionNumber);
            fragment.setArguments(args);
            return fragment;
        }

        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_view_pager_noobs, container, false);
            TextView textView = (TextView) rootView.findViewById(R.id.section_label);
            textView.setText(getString(R.string.section_format, getArguments().getInt(ARG_SECTION_NUMBER)));
            return rootView;
        }
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        public SectionsPagerAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public Fragment getItem(int position) {
            // getItem is called to instantiate the fragment for the given page.
            // Return a PlaceholderFragment (defined as a static inner class below).
            return PlaceholderFragment.newInstance(position + 1);
        }

        @Override
        public int getCount() {
            // Show 3 total pages.
            return 3;
        }

        @Override
        public CharSequence getPageTitle(int position) {
            switch (position) {
                case 0:
                    return "SECTION 1";
                case 1:
                    return "SECTION 2";
                case 2:
                    return "SECTION 3";
            }
            return null;
        }
    }

}