0
내 메인 페이지에 3 개의 버튼이 있습니다. 내가 그들을 클릭하려고하면 이상한 일이 일어난다. 예를 들어, NewGame 버튼을 클릭하면 먼저 점수 버튼에 표시 할 내용이 표시되고, 뒤로 버튼을 클릭하면 해당 버튼의 의도 된 활동이 표시됩니다. [정보] 버튼으로, 나는 두 번 다시 클릭해야 (그것은 newGame 활동과 성적 활동을 표시합니다. 이런 일이 이유가 있나요?Android 버튼이 잘못된 활동을 엽니 다.
public class Sakurame extends Activity implements OnClickListener {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
//set up click listeners for buttons
View HighScoreButton = findViewById(R.id.highscore_button);
HighScoreButton.setOnClickListener(this);
View newButton = findViewById(R.id.new_button);
newButton.setOnClickListener(this);
View aboutButton = findViewById(R.id.about_button);
aboutButton.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu){
super.onCreateOptionsMenu(menu);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
switch (item.getItemId()){
case R.id.settings:
startActivity(new Intent(this, Prefs.class));
return true;
// More items go here (if any)
}
return false;
}
public void onClick(View v){
switch(v.getId()){
case R.id.about_button:
Intent i = new Intent(this, About.class);
startActivity(i);
case R.id.new_button:
Intent i2 = new Intent(this, HighScore.class);
startActivity(i2);
case R.id.highscore_button:
Intent i3 = new Intent(this, DisplayScores.class);
startActivity(i3);
//break;
// more buttons go here (if any)
}
}
그냥 설명 추가 :. 케이스 문의 casca을 드. 따라서 각 case 문 다음에 break를 추가하지 않으면 이후의 모든 case 문이 실행됩니다 ... –
그래, 조금 더 명확하게 만들어야합니다. – keyboardP
감사합니다 - 모든 것을 해결했습니다. 나는 그들이 캐스케이드했다는 것을 몰랐다. @ –