
在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 – 如何从另一个片段更新片段的ListView?全部内容,希望文章能够帮你解决android – 如何从另一个片段更新片段的ListView?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)