如何在运行时向SlidingTabLayout添加选项卡

时间:2015-10-02 18:05:55

标签: android dynamic tabs android-viewpager runtime

我一直试图在运行时将标签添加到SlidingTabLayout是徒劳的。 我从对话框中获取要添加的选项卡的名称。我正在尝试通过获取对活动的ViewPager的引用来更新dialogFragment中的mainActivity的ViewPager:

     ViewPager MyPager= (ViewPager) getActivity().findViewById(R.id.pager);
      MyPager.getAdapter().notifyDataSetChanged();

失败。

A也试过this,但我无法让它工作

      mViewPager = (ViewPager) findViewById(R.id.pager);
      mViewPager.setAdapter(mSectionsPagerAdapter);

      //But here is the problem, I can't find a way to refer to the 
      //Activity's SlidingTabLayout from the DialogFragment.

      tabs = (SlidingTabLayout) findViewById(R.id.tabs);

我希望你能帮助我,谢谢。

0 个答案:

没有答案