Use Tabhost and Fragment to implement the label-based main interface framework-implementing the interface stack (Android study notes)

Source: Internet
Author: User

 

  Tucao

I used a stack to manage multiple Fragment jumps. Now I found everything is so simple, ah, face to face ....

 

The add, remove, and replace operations on Fragment are all performed through the FragmentTransaction transaction. After beginTransaction

Execute a series of Fragment operations. Before committing, if you use the addToBackStack function, you can save the transaction operation in the stack. So that when you press

When the back button is used, it can restore the transaction operation so that the interface returns to the status before this transaction. The result is equivalent to returning the previous Activity.

This article implements multi-layer jump and return of the tab framework.

  

      replaceTabView( containerViewID, Fragment frag, String tag, = =

 

In actual use, we often need to switch the view on the current tab. For example, you can click a news item in the list on the News tab to go to the details page. Therefore, it is much easier to add the following functions to replace the current interface.

(MTabHost is your TabHost instance ):

  

     

During the simulation, I added a jump button to a Fragment to jump to the second Fragment. Here I use FirstPageFragment

Jump to SecondFloorFragment.

  

  SecondFloorFragment(), "second"

Now, by adding the above code, you can jump to SecondFloorFragment in FirstPageFragment, and when you press the return key, you can return to FirstPageFragment.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.