<legend id='JYwBN'><style id='JYwBN'><dir id='JYwBN'><q id='JYwBN'></q></dir></style></legend>
    • <bdo id='JYwBN'></bdo><ul id='JYwBN'></ul>

    1. <tfoot id='JYwBN'></tfoot>

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

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

        在片段中显示片段查看器

        时间:2023-10-04
          <bdo id='L0Xcq'></bdo><ul id='L0Xcq'></ul>
          <legend id='L0Xcq'><style id='L0Xcq'><dir id='L0Xcq'><q id='L0Xcq'></q></dir></style></legend><tfoot id='L0Xcq'></tfoot>

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

              1. <small id='L0Xcq'></small><noframes id='L0Xcq'>

                    <tbody id='L0Xcq'></tbody>
                  本文介绍了在片段中显示片段查看器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个包含 ViewPager 的片段.ViewPager 与包含一组片段的适配器相关联.

                  I have a fragment which contains a ViewPager. The ViewPager is associated with an adapter that contains a set of fragments.

                  在加载父片段时,我遇到了一个 IllegalStateException 消息:java.lang.IllegalStateException: Recursive entry to executePendingTransactions.

                  Upon loading the parent fragment, I am met with an IllegalStateException with the message: java.lang.IllegalStateException: Recursive entry to executePendingTransactions.

                  一些研究使我得出结论,系统无法在另一个片段中显示片段,但是似乎有迹象表明使用 ViewPager 可以做到这一点(ViewPager 与其他片段一起使用的错误).

                  Some research has led me to the conclusion that the system is unable display fragments within another fragment, HOWEVER there seems to be some indication that it is possible to do exactly this with the use of a ViewPager (A bug in ViewPager using it with other fragment).

                  事实上,如果我向我的父片段添加一个按钮,该按钮在按下时在我的 ViewPager 上调用 mPager.setAdapter(mAdapter),则 ViewPager 会成功加载.这并不理想.

                  In fact, if I add a button to my parent fragment which calls mPager.setAdapter(mAdapter) on my ViewPager when pressed, the ViewPager successfully loads. This is not ideal.

                  那么问题必须与片段生命周期有关.因此,我的问题是:有没有其他人找到解决这个问题的方法,如果有,如何解决?

                  The issue then must be related to the fragment lifecycle. My question therefore, is this: Has anybody else found a way around this issue, and if so, how?

                  有什么方法可以将 ViewPager 上的适配器设置延迟到片段事务之后?

                  Is there some way to delay settings the adapter on the ViewPager until after the fragment transaction?

                  这是我的父片段代码:

                      @Override
                  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                  
                      mView = inflater.inflate(R.layout.team_card_master, container, false);
                      mViewPager = (ViewPager)mView.findViewById(R.id.team_card_master_view_pager);
                  
                      final Button button = (Button)mView.findViewById(R.id.load_viewpager_button);
                      button.setOnClickListener(new OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              mViewPager.setAdapter(mAdapter);
                              button.setVisibility(View.GONE);
                          }
                      });
                  
                      mAdapter = new ViewPagerAdapter(getFragmentManager());
                   //     mViewPager.setAdapter(mAdapter);
                  
                      return mView;
                  }
                  

                  还有适配器:

                  public class ViewPagerAdapter extends FragmentPagerAdapter {
                      public ViewPagerAdapter(FragmentManager fm) {
                          super(fm);
                      }
                  
                      @Override
                      public int getCount() {
                          if (mCursor == null) return 0;
                          else return mCursor.getCount();
                      }
                  
                      @Override
                      public Fragment getItem(int position) {
                          Bundle b = createBundle(position, mCursor);
                          return TeamCardFragment.newInstance(b);
                      }
                  }
                  

                  推荐答案

                  使用 AsyncTask 设置 viewPager 的适配器.这个对我有用.asyncTask 是为了使原始片段完成它的转换.然后我们继续 viewPager 片段,基本上是为了避免递归.

                  use AsyncTask to set the adapter for viewPager. It works for me. The asyncTask is to make the original fragment complete it's transition. and then we proceed with viewPager fragments, basically to avoid recursion.

                   @Override
                  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
                  
                      mView = inflater.inflate(R.layout.team_card_master, container, false);
                      mViewPager = (ViewPager)mView.findViewById(R.id.team_card_master_view_pager);
                  
                      final Button button = (Button)mView.findViewById(R.id.load_viewpager_button);
                      button.setOnClickListener(new OnClickListener() {
                          @Override
                          public void onClick(View v) {
                              mViewPager.setAdapter(mAdapter);
                              button.setVisibility(View.GONE);
                          }
                      });
                  
                      mAdapter = new ViewPagerAdapter(getFragmentManager());
                      new setAdapterTask().execute();
                  
                      return mView;
                  }
                  
                  private class setAdapterTask extends AsyncTask<Void,Void,Void>{
                        protected Void doInBackground(Void... params) {
                              return null;
                          }
                  
                          @Override
                          protected void onPostExecute(Void result) {
                                     mViewPager.setAdapter(mAdapter);
                          }
                  }
                  

                  这篇关于在片段中显示片段查看器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android Viewpager 作为图片幻灯片库 下一篇:如何让我的 ViewPager 一次只加载一个页面,即 setOffscreenPageLimit(0);

                  相关文章

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

                  <legend id='0N5oF'><style id='0N5oF'><dir id='0N5oF'><q id='0N5oF'></q></dir></style></legend>
                1. <tfoot id='0N5oF'></tfoot>

                    1. <small id='0N5oF'></small><noframes id='0N5oF'>