android – 如何从另一个片段更新片段的Lis​​tView?

android – 如何从另一个片段更新片段的Lis​​tView?,第1张

概述如何在另一个片段中的片段事件之后传达ListFragment的列表视图? 在ListFragment(片段A)中,我有一个刷新ListView的方法.但是,我需要在片段内点击一个按钮后刷新它,它是另一个片段的子节点(片段b) 它像Fragment A(listFragment)|片段B(详细视图)                                     (片段C – B的子片段) 如何在另一个片段中的片段事件之后传达ListFragment的列表视图?

在ListFragment(片段A)中,我有一个刷新ListVIEw的方法.但是,我需要在片段内点击一个按钮后刷新它,它是另一个片段的子节点(片段b)

它像Fragment A(ListFragment)|片段B(详细视图)
                                    (片段C – B的子片段)

我该怎么做?

解决方法 您可以通过其标记访问另一个片段:

// find your fragment YourFragment f = (YourFragment) getSupportFragmentManager().findFragmentByTag("yourFragTag"); // update the List vIEw f.updateListVIEw();

片段的标记在附加到容器布局时设置:

FragmentManager fm = getSupportFragmentManager();fm.beginTransaction().replace(R.ID.frameBuy,YourFragment.newInstance(),"yourFragTag").commit();

因此,当您单击按钮时,找到要通过其标记刷新的片段,然后调用您的刷新方法.

如果您使用的是VIEwPager,这是获取Fragments标记的方法:

/**     * Gets the fragment tag of a fragment at a specific position in the vIEwpager.     *     * @param pos the pos     * @return the fragment tag     */    public String getFragmentTag(int pos){        return "androID:switcher:"+R.ID.yourVIEwPagerID+":"+pos;    }
总结

以上是内存溢出为你收集整理的android – 如何从另一个片段更新片段的Lis​​tView?全部内容,希望文章能够帮你解决android – 如何从另一个片段更新片段的Lis​​tView?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1129416.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-30
下一篇2022-05-30

发表评论

登录后才能评论

评论列表(0条)

    保存