以下のように SharedPreferences を設定しました。
Editor editor = getSharedPreferences("FileName", MODE_PRIVATE).edit();
editor.clear();
editor.putString("chicago", "Chicago, IL");
editor.putString("london", "London, UK");
editor.putString("sanjose", "San Jose, CA");
editor.putString("washington", "Dulles, VA");
editor.commit();
現時点では、AlertDialog を配列から生成しています。SharedPreferences ファイルを使用して、最終的に項目などを動的に追加できるようにしたいと考えています。
現時点で入力するために使用するコードは次のとおりです。
private void openServerDialog() {
new AlertDialog.Builder(this)
.setTitle(R.string.server_title)
.setItems(R.array.serverchoice,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialoginterface,
int i) {
setServer(i);
}
})
.show();
}
したがって、配列「serverchoice」の使用をやめ、代わりに SharedPreferences ファイルの文字列を使用したいだけです。
前もって感謝します