Android Studio/Java는 초보자이므로 질문이 다소 어리 석다면 용서해주세요.계속 버튼 사용/사용 안 함
나는 간단한 수수께끼 게임 인 나의 첫 번째 앱을 거의 끝냈다. 질문이 제기되고 올바른 답을 얻으면 다음 활동을 시작합니다. 주 메뉴에는 평소와 같이 새 게임과 계속 두 가지 옵션이 있습니다. 계속 버튼은 공유 환경 설정을 사용하여 매력처럼 작동합니다.이 버튼을 누르면 대답하지 않은 마지막 질문으로 이동합니다.
내 문제는 : 기본적으로 계속 단추를 사용할 수 없도록 설정 한 다음 첫 번째 질문에 답하면 사용할 수 없습니다. 글쎄, 진실은 내가 그것을 사용하지 않도록 설정할 수 있습니다.
@Override
public void onResume() {
super.onResume();
setContentView(R.layout.activity_main_menu_with_logo);
mContinueButton = (Button)findViewById(R.id.ContinueButton);
mContinueButton.setEnabled(false);
...
}
그러나 나중에 사용할 수 있도록 설정할 방법을 찾지 못했습니다. 나는 그것을 "public void 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 = (버튼) findViewById를 (R.id.ContinueButton) (false)를 mContinueButton.setEnabled, mContinueButton.setEnabled을 (참된);" onResume()에서 을 제거하고 "mContinueButton.setEnabled (true);"를 제거합니다. onClick()의 줄? 아니면 다른 활동을 변경해야합니까? 왜냐하면 나는 당신이 말한 것을했기 때문에 버튼은 항상 활성화되어 있습니다. 또한, mContinueButton.setEnabled (false); 노란색 상자에 나타납니다 : http://i.imgur.com/wfbjWPV.jpg – Animated24
답변에 대한 자세한 내용을 추가했습니다. – greeble31