I have created tab layout and in one fragment I am using button to transfer data to other fragment that is on second position of tablayout. So when I will click on a button in first fragment then a text string should be sent to second fragment and should be shown in a textview in that fragment.
Question posted in Android Studio
The official documentation can be found here.
The official documentation can be found here.
2
Answers
Either put those data in a variable in activity and fragments can access that data from parent Activity..
or use a Shared View Model.
If you are transferring data like int,long,String etc. Then you can wrap your data in Bundle while creating the second Fragment and get all data in the second Fragment in its onCreate() method using getArguments() method.
In your first fragment in the onClick(View view) method-
And then in onCreate(Bundle savedInstanceState) method of the YourSecondFragment
Finally in the onCreateView() method of secondFragment-