Android Studio textview text isn't changing when I use setText in custom method

688 views Asked by At

I'm using the following to change a symbol:

private void updateCurrencySymbol() {
    SharedPreferences sharedPreferences  = PreferenceManager.getDefaultSharedPreferences(this);

    String symbol = sharedPreferences.getString("preferences_currency", "$");
    Toast.makeText(getApplicationContext(),symbol,Toast.LENGTH_LONG).show();
    currencySymbol1 = (TextView) findViewById(R.id.currencySymbol1);
    currencySymbol2 = (TextView) findViewById(R.id.currencySymbol2);
    currencySymbol1.setText(symbol);
    currencySymbol2.setText(symbol);
    //refreshes the activity
    Bundle temp_bundle = new Bundle();
    onSaveInstanceState(temp_bundle);
    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("bundle", temp_bundle);
    startActivity(intent);
    finish();
}

In the Toast it shows the right symbol that I chose from the settings but it never changes in the actual TextView. I tried changing the text in the onCreate() method and it works, changing to the string I specify.

1

There are 1 answers

3
EE66 On BEST ANSWER

It wont chagne becuase the data at SharedPreferences doesnt change. There is no need to restart the activity. No need AT ALL. Just setText() the textview. then save to sharedPrefrences for future starts.