Pass data between fragments

前端 未结 2 968
日久生厌
日久生厌 2020-12-11 05:49

I want to transfer the user ID from the main Activity to a fragment.

So in the main activity, I do:

 Fragment fragment = new Fragment();
 final Bund         


        
相关标签:
2条回答
  • 2020-12-11 06:10

    You can use:

     Bundle args = getArguments();
     if (args  != null && args.containsKey("id_User"))
         String userId = args.getString("id_User");
    
    0 讨论(0)
  • 2020-12-11 06:17

    Just use:

    String User = getArguments().getString("id_User", "Default Value");
    

    The default value you supply will be returned if the key you request does not exist.

    0 讨论(0)
提交回复
热议问题