The TabHost implemented by Android ActivityGroup retains the original status of the activity.

Source: Internet
Author: User

When TabHost implemented by ActivityGroup is switched from tab1 to tab2, the activity in tab1 is reloaded.

Public class MainUIActivity extends ActivityGroup {private Context context = this; private TabHost mTabhost; private String TAB1 = "Homepage"; private String TAB2 = "favorites"; private String TAB3 = "3 "; private String TAB4 = "4"; private String TAB5 = "more"; // define an array to store the button image private int mImageViewArray [] = {R. drawable. tab_home_btn, R. drawable. tab_message_btn, R. drawable. tab_selfinfo_btn, R. drawable. tab_square_btn, R. drawable. tab_more_btn}; // The text of the Tab is private String mTextviewArray [] = {TAB1, TAB2, TAB3, TAB4, TAB5}; @ Overrideprotected void onCreate (Bundle savedInstanceState) {// TODO Auto-generated method stubsuper. onCreate (savedInstanceState); setContentView (R. layout. tab_main); mTabhost = (TabHost) findViewById (R. id. tabhost1); mTabhost. setup (); mTabhost. setup (this. getLocalActivityManager (); Intent i1 = new Intent (this, MainActivity. class); Intent I _collect = new Intent (this, CollectActivity. class); // Intent i1 = new Intent (this, MainActivity. class); // Intent i1 = new Intent (this, MainActivity. class); // Intent i1 = new Intent (this, MainActivity. class); mTabhost. addTab (mTabhost. newTabSpec (TAB1 ). setIndicator (getTabItemView (0 )). setContent (R. id. zhuye ). setContent (i1); // Note: newTabSpec (TAB2) is used here. Each tab must be written differently so that the original status mTabhost can be saved. addTab (mTabhost. newTabSpec (TAB2 ). setIndicator (getTabItemView (1 )). setContent (R. id. zhuye2 ). setContent (I _collect); mTabhost. addTab (mTabhost. newTabSpec (TAB1 ). setIndicator (getTabItemView (2 )). setContent (R. id. zhuye3 ). setContent (i1); mTabhost. addTab (mTabhost. newTabSpec (TAB1 ). setIndicator (getTabItemView (3 )). setContent (R. id. zhuye4 ). setContent (i1); mTabhost. addTab (mTabhost. newTabSpec (TAB1 ). setIndicator (getTabItemView (4 )). setContent (R. id. zhuye5 ). setContent (i1);}/*** set the icon and text for the Tab button */private View getTabItemView (int index) {View view = LayoutInflater. from (context ). inflate (R. layout. tab_item, null); ImageView imageView = (ImageView) view. findViewById (R. id. tab_icon); imageView. setImageResource (mImageViewArray [index]); TextView textView = (TextView) view. findViewById (R. id. tab_name); textView. setText (mTextviewArray [index]); return view;} public static Intent createIntent (Context context) {Intent I = new Intent (context, MainActivity. class); I. addFlags (Intent. FLAG_ACTIVITY_CLEAR_TOP); return I ;}}
The solution has been written in the code above, that is, to set different tags for each tab

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.