Today, let's take a look at the transfer of data between fragment and fragment and the transfer of data with activity.
Here we use the interface method (learning Android requires the basis of java, like me who learns Android in a half-hearted way, it is irritating)
First build a simple interface, the top activity, the following two fragments
First, let's first look at the fragment passing data to the activity.
First come an interface
public interface getMyText {
void getText(String msg);
}
Then the activity implements the interface and rewrites the abstract method. Assign values to the control in the method and
then write the method in the fragment.
Run and click to see the effect, as shown in the figure:
Second, let's look at the communication between fragment and fragment
Implement the interface in the second fragment
and then use the tag to find the second fragment through the activity bridge in the first fragment.
Run, the results are as follows: