简体   繁体   中英

kotlin- Bundle pass null to other fragments

我有一个具有1个活动和两个片段的简单应用程序,其中两个片段显示一个RecyclerView并用OnClickListener替换片段,现在我需要通过单击将数组列表RecyclerView的数据发送到其他片段,我不知道必须在哪里键入Bundle如何

Your main culprit is ft1.replace(R.id.MainFram,SubMark()) instead you must use ft1.replace(R.id.MainFram,subMark) subMark variable. You are calling new instance of Fragment instead of fragment with bundle. Use these piece of code

  val bundle = Bundle()
    bundle.putString("data", "nasser") 
    val subMark = SubMark()
    subMark.arguments = bundle
    var ft1 : FragmentTransaction = supportFragmentManager.beginTransaction() 
    ft1.replace(R.id.MainFram,subMark) ft1.commit()

And access data with

 String name = getArguments().getString("key");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM