Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>...it will display the new value if I turn my phone and orientation changes</p> </blockquote> <p>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:</p> <p><a href="http://developer.android.com/guide/topics/resources/runtime-changes.html" rel="nofollow">http://developer.android.com/guide/topics/resources/runtime-changes.html</a></p> <p>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.</p> <p><strong>EDIT</strong></p> <p>Sample code with some logging (I moved the widgets into fields...)</p> <pre><code>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); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload