How to transfer some data to another Fragment?

前端 未结 10 2063
说谎
说谎 2020-11-22 11:41

How to transfer some data to another Fragment likewise it was done with extras for intents?

10条回答
  •  傲寒
    傲寒 (楼主)
    2020-11-22 12:25

    This is how you use bundle:

    Bundle b = new Bundle();
    b.putInt("id", id);
    Fragment frag= new Fragment();
    frag.setArguments(b);
    

    retrieve value from bundle:

     bundle = getArguments();
     if (bundle != null) {
        id = bundle.getInt("id");
     }
    

提交回复
热议问题