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 7673153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:26:46+00:00 2026-05-31T16:26:46+00:00

I am having an issue with my TextView. I have a PlayScreenActivity that displays

  • 0

I am having an issue with my TextView. I have a PlayScreenActivity that displays supplies info. on the top of screen. then I go to the store screen and buy supplies. when I come back all others change but 1 and it will display the new value if I turn my phone and orientation changes, thats the only way I can see the added supplies purchased. Anyone have an Idea why this is happening?

I set screen orientation to portrait to see if it will work if it can’t switch but doesnt fix.

EDIT

Here is a copy of my Activity Code:

public class PlayscreenActivity extends Activity {
Data data_;

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

    ((TextView)findViewById(R.id.lemonsLeftText)).setText(
            "Lemons: "  );
    ((TextView)findViewById(R.id.sugarLeftText)).setText(
            "Sugar: "  );
    ((TextView)findViewById(R.id.iceLeftText)).setText(
            "Ice: "  );        
    ((TextView)findViewById(R.id.cupsLeftText)).setText(
            "Cups: "  );
    ((Button)findViewById(R.id.btnshop)).setOnClickListener(
            new SupplyShopListener());
}
private class SupplyShopListener implements OnClickListener{
      public void onClick(View v){
          Intent i = new Intent(v.getContext(), SupplyShopActivity.class);
          startActivity(i);
          //refreshDisplay();
      }

}

@Override
public void onResume(){
    super.onResume();
    data_ = getData();
    refreshDisplay();
}

@Override
public void onPause(){
    super.onPause();
    saveData();
    refreshDisplay();
}

@Override
public void onConfigurationChanged(Configuration newConfig){
    super.onConfigurationChanged(newConfig);
    //refreshDisplay();
}

private Data getData() {
    GameData player_data = new GameData(this);
    player_data.open();
    Data game_state = new Data(player_data.getGameString());
    player_data.close();
    return game_state;
  }

private void saveData() {
    GameData player_data = new GameData(this);
    player_data.open();
    player_data.setGameString(data_.SerializeGame());
    player_data.close();

}
private void refreshDisplay() {

    NumberFormat nf = NumberFormat.getInstance();
    nf.setMinimumFractionDigits(2);
    nf.setMaximumFractionDigits(2);
    String totalCash = nf.format(data_.cash_);

    ((TextView)findViewById(R.id.lemonsLeftText)).setText(
            "Lemons: "  + Integer.toString(data_.lemons_) );        
    ((TextView)findViewById(R.id.sugarLeftText)).setText(
            "Sugar: "  + Integer.toString(data_.sugar_) );
    ((TextView)findViewById(R.id.iceLeftText)).setText(
            "Ice: "  + Integer.toString(data_.ice_) );
    ((TextView)findViewById(R.id.cupsLeftText)).setText(
            "Cups: "  + Integer.toString(data_.cups_) );
    ((TextView)findViewById(R.id.totalCashText)).setText(
            "Cash : "  + (totalCash) );

}

}

  • 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-31T16:26:47+00:00Added an answer on May 31, 2026 at 4:26 pm

    …it will display the new value if I turn my phone and orientation changes

    Android will destroy and re-create the activity when run-time configuration changes occur. It makes sense that your new variables are being drawn on screen rotation, because the entire activity is re-created:

    http://developer.android.com/guide/topics/resources/runtime-changes.html

    If most of your TextView widgets are updating when your PlayScreenActivity is resumed, your refreshDisplay() call is working (to a degree). Which widget doesn’t redraw? I’d also throw in some logging and watch the LogCat like zapl suggested.

    EDIT

    Sample code with some logging (I moved the widgets into fields…)

    public class PlayscreenActivity extends Activity
    {
        Data data_;
    
        String TAG = "PlayScreenActivity";
    
        TextView lemonsLeftTextLabel;
        TextView sugarLeftTextLabel;
        TextView iceLeftLabel;
        TextView cupsLeftTextLabel;
        TextView totalCashTextLabel;
        Button shopButton;
    
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Log.d(TAG, "Creating PlayScreen activity...");
            setContentView(R.layout.main);
    
            Log.d(TAG, "Assigning buttons...");
            lemonsLeftTextLabel = (TextView) findViewById(R.id.lemonsLeftText);
            sugarLeftTextLabel = (TextView) findViewById(R.id.sugarLeftText);
            iceLeftLabel = (TextView) findViewById(R.id.iceLeftText);
            cupsLeftTextLabel = (TextView) findViewById(R.id.cupsLeftText);
            totalCashTextLabel = (TextView) findViewById(R.id.totalCashText);
    
            shopButton = (Button) findViewById(R.id.btnshop);
    
            lemonsLeftTextLabel.setText("Lemons: ");
            sugarLeftTextLabel.setText("Sugar: ");
            iceLeftLabel.setText("Ice: ");
            cupsLeftTextLabel.setText("Cups: ");
    
            shopButton.setOnClickListener(new SupplyShopListener());
            Log.d(TAG, "onCreate() complete");
        }
        private class SupplyShopListener implements View.OnClickListener {
            public void onClick(View v){
                //Intent i = new Intent(v.getContext(), SupplyShopActivity.class);
                //startActivity(i);
                refreshDisplay();
            }
        }
    
        @Override
        public void onResume(){
            Log.d(TAG, "onResume() called");
            super.onResume();
            data_ = getData();
            Log.d(TAG, "Data fetched");
            Log.d(TAG, "Contents of data = " +
                    "Lemons: " + Integer.toString(data_.lemons_) + " | " +
                    "Sugar: " + Integer.toString(data_.sugar_) + " | " +
                    "Ice: " + Integer.toString(data_.ice_) + " | " +
                    "Cups: " + Integer.toString(data_.cups_) + " | " +
                    "Cash: " + data_.cash_ + " | ");
    
            refreshDisplay();
        }
    
        @Override
        public void onPause(){
            Log.d(TAG, "onPause() called");
            super.onPause();
            saveData();
            refreshDisplay();
        }
    
        @Override
        public void onConfigurationChanged(Configuration newConfig){
            Log.d(TAG, "onConfigurationChanged() called");
            super.onConfigurationChanged(newConfig);
        }
    
        private Data getData() {
            Log.d(TAG, "getData() called - restoring");
            GameData player_data = new GameData(this);
            player_data.open();
            Log.d(TAG, "Pulling data from game string...");
            Data game_state = new Data(player_data.getGameString());
            player_data.close();
            Log.d(TAG, "Contents of data = " +
                    "Lemons: " + Integer.toString(game_state.lemons_) + " | " +
                    "Sugar: " + Integer.toString(game_state.sugar_) + " | " +
                    "Ice: " + Integer.toString(game_state.ice_) + " | " +
                    "Cups: " + Integer.toString(game_state.cups_) + " | " +
                    "Cash: " + game_state.cash_ + " | ");
            return game_state;
        }
    
        private void saveData() {
            Log.d(TAG, "saveData() called - saving");
            GameData player_data = new GameData(this);
            player_data.open();
            Log.d(TAG, "Serializing data into GameData object");
            Log.d(TAG, "Contents of data = " +
                    "Lemons: " + Integer.toString(data_.lemons_) + " | " +
                    "Sugar: " + Integer.toString(data_.sugar_) + " | " +
                    "Ice: " + Integer.toString(data_.ice_) + " | " +
                    "Cups: " + Integer.toString(data_.cups_) + " | " +
                    "Cash: " + data_.cash_ + " | ");
            player_data.setGameString(data_.SerializeGame());
            player_data.close();
    
        }
        private void refreshDisplay() {
            Log.d(TAG, "refreshDisplay() called - redrawing UI");
    
            NumberFormat nf = NumberFormat.getInstance();
            nf.setMinimumFractionDigits(2);
            nf.setMaximumFractionDigits(2);
            String totalCash = nf.format(data_.cash_);
    
            lemonsLeftTextLabel.setText("Lemons: " + Integer.toString(data_.lemons_));
            sugarLeftTextLabel.setText("Sugar: " + Integer.toString(data_.sugar_));
            iceLeftLabel.setText("Ice: " + Integer.toString(data_.ice_));
            cupsLeftTextLabel.setText("Cups: " + Integer.toString(data_.cups_));
            totalCashTextLabel.setText("Cups: " + totalCash);
    
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having an issue here that I have tried everything I can think of but
I'm having a weird issue with a button that is being shown on screen,
I am having an issue that make me crazy I have a listview with
I'm having an issue with a query that currently uses LEFT JOIN weblog_data AS
I'm having an issue with a standard ASP.NET page that has a TextBox and
Experts, I'm having issue when sending emails out. Currently, I have a feedback form
I'm having the following issue developing in android 2.2 (API 8): I have a
Having an issue with CheckedTextView that I can't seem to find a solution. I'm
I am having issue with git pull.I have commited my changes in local repo.
I am having a strange issue, I have a new asynctask launced whenever i

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.