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

  • Home
  • SEARCH
  • 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 7064865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:53:11+00:00 2026-05-28T04:53:11+00:00

New to Android so I’m writing small programs to get familiar with how things

  • 0

New to Android so I’m writing small programs to get familiar with how things work.
What has been giving me a headache so far are views created at runtime in combination with screen rotation.

After having little luck trying to use parcels, I solved the problem by just recreating the views after a rotation.

The program will add the entered text as a TextView to a TableLayout below the EditText.

Is there a better way of solving this? I could not find any “out of the box” methods for doing this.

public class MWEActivity extends Activity {
    TableLayout table;
    EditText txtInput;
    ArrayList<String> savedEntry = new ArrayList<String>();

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        table = (TableLayout)this.findViewById(R.id.table);
        txtInput = (EditText)this.findViewById(R.id.txtInput);

        txtInput.setOnEditorActionListener(new OnEditorActionListener() {

            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if(event.getKeyCode() == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN){
                        TextView newtext = new TextView(getApplicationContext());
                        newtext.setText(txtInput.getText());
                        savedEntry.add(newtext.getText().toString());
                        table.addView(newtext);
                        txtInput.setText("");
                        return true;
                }
                return false;
            }
        });
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putStringArrayList("entry", savedEntry);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        if(savedInstanceState.getStringArrayList("entry") == null){
            savedEntry = new ArrayList<String>();
            savedEntry.add("Return was NULL");
        }else{
            savedEntry = savedInstanceState.getStringArrayList("entry");
        }

        for(String s : savedEntry){
            TextView tv = new TextView(getApplicationContext());
            tv.setText(s);
            table.addView(tv);
        }
        super.onRestoreInstanceState(savedInstanceState);
    }
}
  • 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-05-28T04:53:12+00:00Added an answer on May 28, 2026 at 4:53 am

    Either you have to disable orientation change like in previous answer, or just rely
    on standard facility. It will pause an then recreate your activity. No extra code is necessary. You can also provide different layouts for different orientations:

    http://developer.android.com/guide/practices/screens_support.html

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

Sidebar

Related Questions

I have been writing apps for my Droid x2 using the new Android update
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html
I'm pretty new to Android dev and still working out a lot of things.
Using my new Android phone established a small problem: I'm living in country A
When creating a new android project, the build target has two choices: Android 2.2,
Just my a new Android phone and I've been tinkering with some basic apps.
I'm a new Android programmer and recently, a lot of my projects have been
I am a relatively new Android developer but have gotten pretty familiar with the
The new Android Market (new sometime July 2011) has a couple of UI patterns
When I start a new Android project in Eclipse (Helios), the strings.xml has 2

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.