码迷,mamicode.com
首页 > 其他好文 > 详细

Activity中通过标签获取当前Fragment

时间:2017-03-04 11:16:57      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:滑动   get   view   pixel   ide   rri   eth   current   初始化   

初始化完成之后才有数据,否则获取不到

  String tag = "android:switcher:"+viewPager.getId()+":"+viewPager.getCurrentItem();

  Fragment fg = getSupportFragmentManager().findFragmentByTag(tag);

  if (fg == null) {
      return;
  }

  switch (viewPager.getCurrentItem()) {
      case 0:
                ((Fragment1)fg).updateUI();
            break;
      case 1:
              ((Fragment2) fg).upDateUI();
         break;
      case 2:
          ((Fragment3) fg).upDateUI();
          break;

  }

 

//ViewPage滑动变化监听

 viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
             //   doSomething
            }

            @Override
            public void onPageSelected(int position) {
                     switch (position){
                      case 0:
                     //   doSomething
                          break;
                      case 1:
                         //   doSomething

                   break;
                      case 2:
                          //   doSomething
                          break;
                  }
              }

            @Override
            public void onPageScrollStateChanged(int state) {
                //完全隐藏或显示时
                if (state == 0) {
                      //   doSomething
                }
             }
     });

 

Activity中通过标签获取当前Fragment

标签:滑动   get   view   pixel   ide   rri   eth   current   初始化   

原文地址:http://www.cnblogs.com/exayong/p/6500508.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!