I have an activity that shows simple 2 TextViews, and get their text from a string array that located in another class.
I am trying to load the first string in the array when loading, and change then the next time the activity is loading change the value in the textview to the string that after the string that I showed first on the textView, and so on.
I change the value of the sharedprefrences but it still only shows me the first string. what is the problem? I change the value of the index of the string array, but it still only shows me the first string.
Thanks in advance
public class DailyMessage extends AppCompatActivity {
public SharedPreferences startExplePref;
String[] DescS;
String[] titleS;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_daily_message);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
startExplePref = PreferenceManager.getDefaultSharedPreferences(this);
boolean isFirstRun = startExplePref.getBoolean("FIRSTRUN", true);
if (isFirstRun) {
SharedPreferences.Editor editor = startExplePref.edit().putBoolean("FIRSTRUN", false);
editor.commit();
startExplePref.edit().putInt("Day",0).commit();
}
TextView titleTV = (TextView)findViewById(R.id.title);
TextView descTV = (TextView)findViewById(R.id.description);
TextView dateTV = (TextView)findViewById(R.id.date);
dateTV.setText(currentDateTimeString);
int dayForTitle = startExplePref.getInt("Day",0);
titleTV.setText(DailyMessagesContent.content[dayForTitle]);
descTV.setText(DailyMessagesContent.content[dayForTitle]);
dayForTitle = dayForTitle++;
startExplePref.edit().putInt("Day",dayForTitle).commit();
}
}
this is the string from the other class:
public static String content[] = {"test1", "test2","test3"};