Switching of multiple fragments in an activity

It is often encountered that multiple fragments are arranged on an activity interface, but how to jump from one fragment to another? Today, I happened to encounter such a problem in the project. Click more stores in the fragment on the home page to switch to the fragment of the store. The processing steps are as follows:

1. Define an interface in a fragment1:

2. Overwrite the onAttach method of fragment. When Fragment is attached to Activity for the first time, it will be called before onCreate.

3. Call the interface where the event is triggered and set parameters:

mListener.setOnClickShopListner(1);

4. Let the activity where the current fragment is located implement this interface.

5. Set the fragment2 to jump in the method of implementing the interface. At this time, click the corresponding control in the fragment to jump and display another activity.

The above is the whole content of this article. I hope the content of this article can bring some help to your study or work. At the same time, I also hope to support a lot of programming tips!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>