Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:40:03+00:00 2026-06-02T13:40:03+00:00

I am adding Views (not Activities) to a TabActivity on demand (meaning that the

  • 0

I am adding Views (not Activities) to a TabActivity on demand (meaning that the activity can have zero or more tabs after onCreate is done). Over the time more tabs get added, now I need to save them in a sane way so I can restore them later on. I tried to use saveHierarchyState etc on the individual views, but they are restored without data from the editTexts etc.

So given that I have a HashMap in the activity which maps from tabkeys to views, how would you save this data and restore it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:40:07+00:00Added an answer on June 2, 2026 at 1:40 pm

    Okay, I got it 🙂

    First I thought I needed to set the IDs of the Views as described here — using this approach Android is able to restore the view states. But since my dynamic tabs all use views from the same layout their children all have the same IDs, so android will overwrite the data (The state is saved in a sparse array according to the view ID, so the IDs should be unique) and all views look the same. I fixed that by manually saving the state of my views and reapplying it via:

    SparseArray<Parcelable> container = new SparseArray<Parcelable>();
    saveHierarchyState(container);
    b.putSparseParcelableArray("state", container);
    restoreHierarchyState(b.getSparseParcelableArray("state"));
    

    While this approach works I still have to find out if I can let Android do all the work by not setting IDs for the Views in the layout xml file (if that’s allowed/possible).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi i have a collection and two views. On my view1 i'm adding data
I have an Android application with a main activity that is the tabhost. I'm
I have a few dozen activities: 1-Main, 1-Animation, 10-Other's and it's sub-sets of more
There's something fundamental that I'm not understanding about presenting views that get their interface
I have a number of views that include tableviews, but other controls as well.
I have an activity in which my views (table and headertable) are overlapping private
I have an InfoListAdapter that uses the following code to populate views in the
Dynamically I am creating the linear layout and adding the views to linear layout
I'm having a memory problem related to UIImageView. After adding this view to my
I have problem adding arraylist to list view, will explain about my problem here..

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.