• <legend id='q4K5q'><style id='q4K5q'><dir id='q4K5q'><q id='q4K5q'></q></dir></style></legend>
  • <tfoot id='q4K5q'></tfoot>

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

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

        <bdo id='q4K5q'></bdo><ul id='q4K5q'></ul>

        如何确定 Fragment 何时在 ViewPager 中可见

        How to determine when Fragment becomes visible in ViewPager(如何确定 Fragment 何时在 ViewPager 中可见)
        <i id='7bevz'><tr id='7bevz'><dt id='7bevz'><q id='7bevz'><span id='7bevz'><b id='7bevz'><form id='7bevz'><ins id='7bevz'></ins><ul id='7bevz'></ul><sub id='7bevz'></sub></form><legend id='7bevz'></legend><bdo id='7bevz'><pre id='7bevz'><center id='7bevz'></center></pre></bdo></b><th id='7bevz'></th></span></q></dt></tr></i><div id='7bevz'><tfoot id='7bevz'></tfoot><dl id='7bevz'><fieldset id='7bevz'></fieldset></dl></div>
            <tbody id='7bevz'></tbody>

          • <tfoot id='7bevz'></tfoot>

            <small id='7bevz'></small><noframes id='7bevz'>

                <bdo id='7bevz'></bdo><ul id='7bevz'></ul>
                <legend id='7bevz'><style id='7bevz'><dir id='7bevz'><q id='7bevz'></q></dir></style></legend>

                  本文介绍了如何确定 Fragment 何时在 ViewPager 中可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  问题:ViewPager 中的片段 onResume() 在片段实际可见之前被触发.

                  Problem: Fragment onResume() in ViewPager is fired before the fragment becomes actually visible.

                  例如,我有 2 个片段,分别是 ViewPagerFragmentPagerAdapter.第二个片段仅适用于授权用户,我需要在片段可见时要求用户登录(使用警报对话框).

                  For example, I have 2 fragments with ViewPager and FragmentPagerAdapter. The second fragment is only available for authorized users and I need to ask the user to log in when the fragment becomes visible (using an alert dialog).

                  但是 ViewPager 在第一个片段可见时创建第二个片段,以便缓存第二个片段并在用户开始滑动时使其可见.

                  BUT the ViewPager creates the second fragment when the first is visible in order to cache the second fragment and makes it visible when the user starts swiping.

                  所以 onResume() 事件早在第二个片段变得可见之前就在第二个片段中触发了.这就是为什么我试图找到一个在第二个片段可见时触发的事件,以便在适当的时候显示一个对话框.

                  So the onResume() event is fired in the second fragment long before it becomes visible. That's why I'm trying to find an event which fires when the second fragment becomes visible to show a dialog at the appropriate moment.

                  如何做到这一点?

                  推荐答案

                  如何确定 Fragment 何时在 ViewPager 中可见

                  How to determine when Fragment becomes visible in ViewPager

                  您可以通过在 Fragment 中覆盖 setUserVisibleHint 来执行以下操作:

                  You can do the following by overriding setUserVisibleHint in your Fragment:

                  public class MyFragment extends Fragment {
                      @Override
                      public void setUserVisibleHint(boolean isVisibleToUser) {
                          super.setUserVisibleHint(isVisibleToUser);
                          if (isVisibleToUser) {
                          }
                          else {
                          }
                      }
                  }
                  

                  这篇关于如何确定 Fragment 何时在 ViewPager 中可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Android- listview, service mediaplayer, and boolean flags(Android-listview、服务媒体播放器和布尔标志)
                  SharedPreferences amp; boolean(SharedPreferences amp;布尔值)
                  readBooleanArray throws RuntimeException(quot;bad array lengthsquot;)(readBooleanArray 抛出 RuntimeException(“错误的数组长度))
                  CheckBox[] with onClickListener[]?(带有 onClickListener[] 的 CheckBox[]?)
                  Android: How to check if Google is available?(Android:如何检查 Google 是否可用?)
                  android resolve .local (mDNS)(android 解析 .local (mDNS))

                      <bdo id='VUD9r'></bdo><ul id='VUD9r'></ul>
                    • <tfoot id='VUD9r'></tfoot>
                    • <small id='VUD9r'></small><noframes id='VUD9r'>

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