android - 用xml创建的fragment如何进行数据的传递与更新?
阿神
阿神 2017-04-17 17:35:08
0
4
427
   

这是mainactivity的布局,DrawerLayout的左边是一个侧滑菜单,里面是一个fragment,已经写死了,所以不需要初始化,打开程序的时候直接里面一次性更新了数据。

现在通过搜索界面会给mainactivity传递数据,求问怎样才能把数据传给fragment使用?

阿神
阿神

闭关修行中......

reply all (4)
小葫芦

Use FragmentManager to find your Fragment and let it interact with other classes by constructing an interface. Of course, you can directly obtain the Fragment instance and call its methods.

    小葫芦

    Fragments can be loaded this way. transaction.replace(R.id.frame, fragment); Just write a set method in the fragment, so that passing the value is simple.
    I have never tried this kind of writing to death. You can completely use the above method instead

      阿神
      1. Message bus EventBus, otto or RxBus

        刘奇

        The following two methods:
        1. Use event bus EventBus or RxBus
        2. Write the set method in Fragment

          Latest Downloads
          More>
          Web Effects
          Website Source Code
          Website Materials
          Front End Template
          About us Disclaimer Sitemap
          php.cn:Public welfare online PHP training,Help PHP learners grow quickly!