現在、私は、ボタンのテキストを、それが表すブール値に応じて切り替える「トグル」タイプのシステムを適用しようとしています。ボタンのテキストを直ちに変更する
たとえば、ブール値RequestingLU trueの場合、ボタンに「停止」と、偽の場合は「開始」とします。
現在、私はそれをonStart()に入れました。ユーザーが「却下」押した後の変更はすぐに適用されるように、それは私が画面を訪問するたびに、少なくとも更新、
public void onStart() {
super.onStart();
final SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
final SharedPreferences.Editor editor = settings.edit();
final Button StopButton = (Button) findViewById(R.id.StopButton);
boolean RequestingLU = settings.getBoolean("RequestingLU", true);
if (RequestingLU) {
StopButton.setText(R.string.Stop_Button);
StopButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
AlertDialog.Builder StopDialog = new AlertDialog.Builder(MainMenu.this);
StopDialog.setTitle(R.string.Stop_Title);
StopDialog.setMessage(R.string.Stop_Message);
StopDialog.setPositiveButton(R.string.Stop_Button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int id) {
editor.putBoolean("RequestingLU", false);
editor.apply();
Toast.makeText(MainMenu.this, "You have stopped the app", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
StopDialog.setNeutralButton(R.string.Negative_Button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//Closes box
dialog.dismiss();
}
});
StopDialog.create().show();
}
});
}
else {
StopButton.setText(R.string.Start_Button);
StopButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
editor.putBoolean("RequestingLU", true);
editor.apply();
Toast.makeText(MainMenu.this, "You have started the app", Toast.LENGTH_SHORT).show();
}
});
}
}
なるように、私は、ボタンの機能が欲しいです。どうすればこれを達成できますか?
? – Iceman
Woops、私は間違ったものをクリックした; /すみません。 –