1

ViewPager 未显示在 BottomSheetDialog 上。这是实现。

public void show(final BoxItem boxItem) {
        bottomSheet = (mContext).getLayoutInflater().inflate(R.layout.layout_change_size_and_frequency, null);
        bottomSheetDialog.setContentView(bottomSheet);
        bottomSheetDialog.show();
        hashMap = boxItem.getFrequencyItemConfigHashMap();
        initViews();
        setupViewPagerAndTabs();
    }

    private void setupViewPagerAndTabs() {
        Set<String> keySet = hashMap.keySet();
        ViewPagerAdapter adapter = new ViewPagerAdapter(((AppCompatActivity) mContext).getSupportFragmentManager());
        for (String key : keySet) {
            adapter.addFragment(SearchDetailItemsFragment.getInstance(hash.get(key)), key);
        }
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);

    }

    private void initViews() {
        tabLayout = (TabLayout) bottomSheet.findViewById(R.id.tabs);
        viewPager = (ViewPager) bottomSheet.findViewById(R.id.viewPager);
    }
4

1 回答 1

0

对话框上不允许有片段。我通过使用BottomSheetDialogFragment解决了这个问题,它允许做各种事情来保持片段的生命周期。

于 2016-05-26T11:30:52.497 回答