私はAndroid Studio/Javaについては初心者ですので、質問が愚かであれば私を許してください。続行ボタンを無効にする/有効にする
私は単純な謎のゲームである私の最初のアプリをほぼ完成させました。質問が尋ねられており、適切な答えであなたは次の活動に行きます。 メインメニューには、新しいゲームと続行の2つのオプションがあります。 [続行]ボタンは、共有設定を使用してチャームのように機能します。押すと、最後に回答しなかった質問に移動します。
私の問題は次のとおりです。最初の質問に答えると、[続行]ボタンをデフォルトで無効にすることはできません。まあ、真実は、私は
@Override
public void onResume() {
super.onResume();
setContentView(R.layout.activity_main_menu_with_logo);
mContinueButton = (Button)findViewById(R.id.ContinueButton);
mContinueButton.setEnabled(false);
...
}
を使用して、それを無効にすることができますですが、私はそれを後で有効にする方法を発見していません。私は、「公共のボイドのonClick」の下にある
if (!(question00Answered)) {
mContinueButton.setEnabled(true);
Intent intent = new Intent(MainMenuWithLogo.this, Question00.class);
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
を書き込むことによって、それを動作させるだろうと思ったが、いや、それはしていません。質問に答えても、私はまだそれを押すことができません。ですから、私は何を修正すべきですか?どんな種類の助けでも大歓迎です。
MainMenuWithLogo.Java
public class MainMenuWithLogo extends AppCompatActivity {
private Button mStartInterrogationButton;
private VideoView mLogoprwto;
private Button mContinueButton;
MediaPlayer song;
@Override
protected void onPause() {
super.onPause();
song.release();
}
@Override
public void onResume() {
super.onResume();
setContentView(R.layout.activity_main_menu_with_logo);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
song = MediaPlayer.create(this, R.raw.chopin);
song.start();
song.setLooping(true);
mLogoprwto = (VideoView) findViewById(R.id.logoprwto);
mLogoprwto.setVideoPath("android.resource://its_destination/"+R.raw.teloslogo);
mLogoprwto.start();
mLogoprwto.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mLogoprwto.start();
}
});
mStartInterrogationButton = (Button)findViewById(R.id.StartInterrogationButton);
mStartInterrogationButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
startGame();
}
});
mContinueButton = (Button)findViewById(R.id.ContinueButton);
mContinueButton.setEnabled(false);
mContinueButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SharedPreferences prefs = getSharedPreferences("Stage", MODE_PRIVATE);
boolean question00Answered = prefs.getBoolean("QuestionZero", false);
boolean question01Answered = prefs.getBoolean("QuestionOne", false);
boolean question02Answered = prefs.getBoolean("QuestionTwo", false);
if (!(question00Answered)) {
mContinueButton.setEnabled(true);
Intent intent = new Intent(MainMenuWithLogo.this, QuestionZero.class);
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
} else if (!(question01Answered)) {
mContinueButton.setEnabled(true);
Intent intent = new Intent(MainMenuWithLogo.this, QuestionOne.class);
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
} else if (!(question02Answered)) {
mContinueButton.setEnabled(true);
Intent intent = new Intent(MainMenuWithLogo.this, QuestionTwo.class);
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}else {
mContinueButton.setEnabled(true);
Intent intent = new Intent(MainMenuWithLogo.this, End.class);
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
}
});
}
private void startGame() {
Intent intent = new Intent(this, Intro.class);
startActivity(intent);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
finish();
}
@Override
public void onBackPressed() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
}
}
私はこれの背後にある論理を理解し始めます。上記のコードでは、次のように記述する必要があります。 "mContinueButton =(Button)findViewById(R.id.ContinueButton); mContinueButton.setEnabled(false); mContinueButton.setEnabled(真); " onResume()の下で を削除し、 "mContinueButton.setEnabled(true);"を削除します。 onClick()からの行?あるいは他の活動にも変更を加える必要がありますか?なぜなら、あなたが言ったことをやったからです。しかし今、ボタンは常に有効になっています。 また、mContinueButton.setEnabled(false);黄色のボックスに表示されます:http://i.imgur.com/wfbjWPV.jpg – Animated24
私は答えに詳細を追加しました。 – greeble31