単純な 2 つの TextView を表示するアクティビティがあり、別のクラスにある文字列配列からテキストを取得します。読み込み時に配列の最初の文字列を読み込もうとしています。次に、アクティビティが読み込まれるときに、textview の値を、textView で最初に表示した文字列の後の文字列に変更します。sharedprefrences の値を変更しましたが、それでも最初の文字列しか表示されません。何が問題ですか?文字列配列のインデックスの値を変更しましたが、それでも最初の文字列しか表示されません。ありがとうございます。
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();
}
}
これは他のクラスの文字列です:
public static String content[] = {"test1", "test2","test3"};