<tfoot id='BU2jf'></tfoot>

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

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

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

    2. 片段内的Android setShareIntent

      时间:2023-10-03
        <tbody id='7sMN7'></tbody>

        <legend id='7sMN7'><style id='7sMN7'><dir id='7sMN7'><q id='7sMN7'></q></dir></style></legend>

        • <bdo id='7sMN7'></bdo><ul id='7sMN7'></ul>

          <tfoot id='7sMN7'></tfoot>

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

              • <small id='7sMN7'></small><noframes id='7sMN7'>

                本文介绍了片段内的Android setShareIntent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                1.背景

                我有一个屏幕有一个

                ShareActionProvider
                

                还有一个

                ViewPager
                

                使用片段.

                我希望做的是从当前可见的片段中获取一些信息来创建一个意图,然后我就可以在 ShareActionProvider 上设置意图.

                What I was hoping to do was get some information from inside the currently visible fragment to create an intent, I would then be able to set the intent on the ShareActionProvider.

                这是我用来设置 ShareActionProvider 意图的代码:

                This is the code I use to set the intent of the ShareActionProvider:

                    MenuItem actionItem = men.getMenu().findItem(R.id.menu_item_share_action_provider_action_bar);
                    ShareActionProvider actionProvider = (ShareActionProvider) actionItem.getActionProvider();
                    actionProvider.setShareIntent(createShareIntent(mProduct.mProduct));
                

                我已经尝试在几个地方使用它,例如在 Fragment 类的这些函数中:

                I have tried using this in several places such as within these functions of the Fragment class :

                onCreateView
                onStart
                

                我也尝试在 FragmentPagerAdapter 类中的这些函数中使用它:

                I have also tried using it in these functions within the FragmentPagerAdapter class :

                getItem
                

                <强>2.问题

                虽然意图实际上是在 ShareActionProvider 中设置的,但获得的信息是针对下一个片段(当前未显示的片段).例如:

                Although the intent is actually getting set within the ShareActionProvider, the information that is obtained is for the next fragment (the one not currently being shown). For example:

                如果我有 4 个片段:frag1、frag2、frag3、frag4我目前正在查看frag1",ShareActionProvider 将尝试共享frag2".这是真的,直到它到达frag4",它将共享正确的值.

                If I have 4 fragments : frag1, frag2, frag3, frag4 and I am currently viewing "frag1" the ShareActionProvider will attempt to share "frag2". This is true until it reaches "frag4" where it will share the correct value.

                我的猜测是片段分页器创建了当前视图和下一个视图(隐藏),这反过来又设置了 ShareActionProvider.如果是这种情况,那么setShareIntent"的正确位置在哪里?

                My guess is that the fragment pager creates the current view and the next view (hidden), which is in turn setting the ShareActionProvider. If this is the case then where is the correct place to "setShareIntent"?

                推荐答案

                我自己设法弄清楚了如何做到这一点.我最终做的是覆盖

                I managed to figure out how to do this myself. What I ended up doing is overriding the

                OnPageChangeListener
                

                在fragmentactivity中

                in the fragmentactivity

                private final OnPageChangeListener mOnPageChangeListener = new OnPageChangeListener() {
                
                    @Override
                    public void onPageScrollStateChanged(int arg0) {
                        // TODO Auto-generated method stub
                    }
                
                    @Override
                    public void onPageScrolled(int arg0, float arg1, int arg2) {
                        // TODO Auto-generated method stub
                
                    }
                
                    @Override
                    public void onPageSelected(int arg0) {
                        // TODO Auto-generated method stub
                        TestFragment frag = (TestFragment) adapter.mFragments.get(pager.getCurrentItem());
                
                        frag.setShareActionIntent();
                
                    }
                
                };
                

                这篇关于片段内的Android setShareIntent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Android ViewPager 方向改变 下一篇:java.lang.IndexOutOfBoundsException:索引 7 无效,大小为 7

                相关文章

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

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

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

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