Android如何在alertdialog中实现viewerpage

时间:2017-03-01 09:02:16

标签: android android-layout android-viewpager fragment alertdialog

enter image description here 我设法在我的警报框中插入一个viewpager,但是当我运行它时没有 在我的alertdialog功能甚至刷到选项卡2也没有工作。是我处理viewpager的方法是错误的,还是有另一种方法来处理alertdialog中的viewpager.Any建议来解决我的问题

LayoutInflater li = LayoutInflater.from(getActivity());
         View promptsView = li.inflate(R.layout.prompt_quantity, null);
         final AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
         // set prompts.xml to alertdialog builder
         alertDialogBuilder.setView(promptsView);
         final GridView modifiergridview = (GridView) promptsView.findViewById(R.id.modifiergridview);
         modifierList = db.getModifierName(pName);
         modifiergridview.setAdapter(new Modifierlist());

          mAdapter = new TabsPagerAdapter(getActivity().getSupportFragmentManager());
                                viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

                                    @Override
                                    public void onPageSelected(int position) {

                                        btnAction(position);

                                    }

                                    @Override
                                    public void onPageScrolled(int arg0, float arg1, int arg2) {
                                    }

                                    @Override
                                    public void onPageScrollStateChanged(int arg0) {
                                    }
                                });
                                viewPager.setAdapter(mAdapter);


          alertDialog.show();
          alertDialog.getWindow().setLayout(2000, 2000);



   }

});

TabsPagerAdapter

public class TabsPagerAdapter extends FragmentPagerAdapter {

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

@Override
public Fragment getItem(int index) {

    switch (index) {
    case 0:

        return new Tab1();
    case 1:

        return new Tab2(); 
    case 2:

        return new Tab3();
    }

    return null;
}

@Override
public int getCount() {

    return 3;
}

}

0 个答案:

没有答案