Pass data between two fragments without using activity

前端 未结 3 657
执念已碎
执念已碎 2020-12-03 13:17

I want to pass data between two fragments without using activity and fragment activity.

I don\'t want to pass data between fragments using activity like this : Commu

3条回答
  •  难免孤独
    2020-12-03 13:36

    I think you are trying to pass data from one fragment to another fragment, So try using below code.

    Use a Bundle, So write below code in first fragment from where you want to send data.

    Fragment fragment = new Fragment();
    Bundle bundle = new Bundle();
    bundle.putString("message", "From Activity");
    fragment.setArguments(bundle);
    

    and to retrieve that data, use the following code in your other fragment

    String strtext=getArguments().getString("message");
    

提交回复
热议问题