• <bdo id='BZMzu'></bdo><ul id='BZMzu'></ul>

        <tfoot id='BZMzu'></tfoot>

        <legend id='BZMzu'><style id='BZMzu'><dir id='BZMzu'><q id='BZMzu'></q></dir></style></legend>
        <i id='BZMzu'><tr id='BZMzu'><dt id='BZMzu'><q id='BZMzu'><span id='BZMzu'><b id='BZMzu'><form id='BZMzu'><ins id='BZMzu'></ins><ul id='BZMzu'></ul><sub id='BZMzu'></sub></form><legend id='BZMzu'></legend><bdo id='BZMzu'><pre id='BZMzu'><center id='BZMzu'></center></pre></bdo></b><th id='BZMzu'></th></span></q></dt></tr></i><div id='BZMzu'><tfoot id='BZMzu'></tfoot><dl id='BZMzu'><fieldset id='BZMzu'></fieldset></dl></div>

        <small id='BZMzu'></small><noframes id='BZMzu'>

      1. 使用 fragmentStatePagerAdapter 更新 viewpager 中的片段/视图

        时间:2023-10-04
          <i id='qYlda'><tr id='qYlda'><dt id='qYlda'><q id='qYlda'><span id='qYlda'><b id='qYlda'><form id='qYlda'><ins id='qYlda'></ins><ul id='qYlda'></ul><sub id='qYlda'></sub></form><legend id='qYlda'></legend><bdo id='qYlda'><pre id='qYlda'><center id='qYlda'></center></pre></bdo></b><th id='qYlda'></th></span></q></dt></tr></i><div id='qYlda'><tfoot id='qYlda'></tfoot><dl id='qYlda'><fieldset id='qYlda'></fieldset></dl></div>

          • <bdo id='qYlda'></bdo><ul id='qYlda'></ul>

                <legend id='qYlda'><style id='qYlda'><dir id='qYlda'><q id='qYlda'></q></dir></style></legend>

                <tfoot id='qYlda'></tfoot>

                  <tbody id='qYlda'></tbody>

                <small id='qYlda'></small><noframes id='qYlda'>

                1. 本文介绍了使用 fragmentStatePagerAdapter 更新 viewpager 中的片段/视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  需要一些帮助来解决我在使用 viewpager 时更新页面的问题.我正在使用带有 FragmentStatePagerAdapter 的简单 viewpager.我想要做的就是访问当前的片段/视图,以便我可以更新我的片段/视图中的一些文本视图.我在论坛里搜索了一下,知道的东西很少- 处理此问题的方法之一是在适配器的 instanceiteItem() 回调中设置标记并通过 findViewbyTag 检索视图.我无法理解如何实现这一点,我也不确定这是否适用于 FragmentStatePagerAdapter.- 我探索了各种论坛中建议的其他选项,但无法使它们发挥作用.

                  Need some help with my problem of updating pages while using viewpager. I am using a simple viewpager with FragmentStatePagerAdapter. All I want to do is get access to the current fragment/view so as I can update some textviews in my fragment/view. I searched around in the forum and came to know few things - One of the ways to handle this is by setting tag in instantiateItem() call back of the adapter and retreive the view by findViewbyTag. I could not understand how to implement this and I am also not sure if that will work for FragmentStatePagerAdapter. - I explored other options as suggested in various forums, but cannot make them work.

                  我的代码与 android http://developer.android.com/training 中的代码非常相似/animation/screen-slide.html.基本组件是相同的(带有一些显示组件的片段活动 xml,包括 textview、viewpager xml,其中只有一个视图分页器、一个 Fragment 类和主要的 FragmentActivity 类).在我的 FragmentActivity 类中,我向我的 viewpager 添加了一个 pageChangelistener,以便我可以在 onPageSelected() 期间更改我的 textview.

                  My code is very much same as in a android http://developer.android.com/training/animation/screen-slide.html. Basic components are the same (Fragment activity xml with some display components including a textview, viewpager xml with just a view pager in it, a Fragment class and the main FragmentActivity class). in my FragmentActivity class I have added a pageChangelistener to my viewpager so as I can do my textview changes during onPageSelected().

                  感谢任何帮助.

                  添加代码供参考.

                  Public class myActivity extends FragmentActivity
                    //Variable declarations
                    protected void onCreate(Bundle savedInstanceState) {
                    ViewPager mPager = (ViewPager) findViewById(R.id.pager);
                    mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
                    mPager.setAdapter(mPagerAdapter);
                    View CurrView;
                  
                    OnPageChangeListener pageChangelistener = new OnPageChangeListener() {
                      @Override
                      public void onPageSelected(int pageSelected) {
                         doTextViewChnges();//access the text view and update it based on pageSelected
                  
                     ---THIS IS WHERE I AM STUCK IN TRYING TO GET THE TEXTVIEW IN MY CURRENT FRAGMWNT/VIEW-------
                     }
                  
                    mPager.setOnPageChangeListener(pageChangelistener);
                   }
                    private class ScreenSlidePagerAdapter extends FragmentStatePagerAdapter { 
                      public ScreenSlidePagerAdapter(android.support.v4.app.FragmentManager  fm) {
                          super(fm);
                      }
                  
                      @Override
                      public android.support.v4.app.Fragment getItem(int position) { 
                          return ScreenSlidePageFragment.create(position, <other parameters I want to pass>);
                      }
                  
                      @Override
                      public int getCount() {
                          return NUM_PAGES;
                      }
                  }
                  

                  推荐答案

                  在你的 OnPageChangeListener 中:

                  in your OnPageChangeListener:

                        OnPageChangeListener pageChangelistener = new OnPageChangeListener() {
                              @Override
                              public void onPageSelected(int pageSelected) {
                   ScreenSlidePageFragment currentFragment = (ScreenSlidePageFragment) mPagerAdapter.getItem(pageSelected)
                                 doTextViewChnges();//access the text view and update it based on pageSelected
                  
                             ---THIS IS WHERE I AM STUCK IN TRYING TO GET THE TEXTVIEW IN MY CURRENT FRAGMWNT/VIEW-------
                             }
                  

                  这篇关于使用 fragmentStatePagerAdapter 更新 viewpager 中的片段/视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:getChildFragmentManager() 方法未定义 下一篇:工具栏和选项卡之间的线

                  相关文章

                2. <small id='EqOop'></small><noframes id='EqOop'>

                  1. <legend id='EqOop'><style id='EqOop'><dir id='EqOop'><q id='EqOop'></q></dir></style></legend>
                      • <bdo id='EqOop'></bdo><ul id='EqOop'></ul>
                    1. <i id='EqOop'><tr id='EqOop'><dt id='EqOop'><q id='EqOop'><span id='EqOop'><b id='EqOop'><form id='EqOop'><ins id='EqOop'></ins><ul id='EqOop'></ul><sub id='EqOop'></sub></form><legend id='EqOop'></legend><bdo id='EqOop'><pre id='EqOop'><center id='EqOop'></center></pre></bdo></b><th id='EqOop'></th></span></q></dt></tr></i><div id='EqOop'><tfoot id='EqOop'></tfoot><dl id='EqOop'><fieldset id='EqOop'></fieldset></dl></div>
                      <tfoot id='EqOop'></tfoot>