그래서 화면 크기가 4 인치 미만이지만 특정 버튼에만 해당하는 장치에서는 작동하지 않는 버튼에 대해 onClickListener를 설정하는 코드가 있습니다. 왜 OS 레벨 버전이 아닌 화면 크기로만 보이기 때문에 왜 그런지는 잘 모르겠습니다.작은 화면 크기에서 OnclickListener가 작동하지 않습니까?
나는 new_game 버튼을 제외한 모든 버튼이 올바르게 등록되고 실행되는 것을 보여주는 onclick 메소드에 로깅 코드를 가지고 있습니다. 이것이 일어날 수있는 이유에 대한 모든 의견을 주시면 감사하겠습니다. 한 OnCreate에서
코드 :
Button acknowledgements = (Button) findViewById(R.id.acknolwedgments_word_Game);
acknowledgements.setOnClickListener(this);
Button quit = (Button) findViewById(R.id.quit_word_game_button);
quit.setOnClickListener(this);
Button new_game = (Button) findViewById(R.id.word_game_new_Button);
Log.e("NEW GAME BUTTON", String.valueOf(new_game));
new_game.setOnClickListener(this);
Log.e("SET ONCLICK", "DONE");
OnClickListener를 :
public void onClick(View view) {
int id = view.getId();
Log.e("CLICKED BUTTON", String.valueOf(view));
if (id == R.id.quit_word_game_button){
Intent i = new Intent(this, Game.class);
startActivity(i);
}
else if (id == R.id.acknolwedgments_word_Game){
Intent i = new Intent(this, Acknowledgements.class);
startActivity(i);
}
else if (id == R.id.word_game_new_Button){
final AlertDialog alert = new AlertDialog.Builder(word_game_mainscreen.this).create();
final EditText edit = new EditText(getBaseContext());
edit.setHint("Username");
alert.setView(edit);
alert.setButton(DialogInterface.BUTTON_NEGATIVE, "CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
alert.dismiss();
}
});
alert.setButton(DialogInterface.BUTTON_POSITIVE, "PLAY!", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
final String opponent = String.valueOf(edit.getText());
new AsyncTask(){
@Override
protected Object doInBackground(Object[] objects) {
//Code to synchronize it to a server
}
@Override
protected void onPostExecute(Object o) {
super.onPostExecute(o);
Log.e("POST EXECUTE", (String)o);
//Creates intent to take you to the game
}
}.execute();
}
});
alert.show();
}
else if (id == R.id.togglesound){
ToggleButton music = (ToggleButton) findViewById(R.id.togglesound);
if (music.isChecked()){
Music.play(this, R.raw.wordgame);
}
else{
Music.stop(this);
}
}
}
내가 작은 규모의 저밀도 화면의 버튼 위에 배치 된 채워지지 않은 스크롤 뷰가 있었다 밝혀 :
AlertDialog을 보여주는를 들어 우리가 처음처럼 builder.Something을 만들어야합니다. 위의 코드에 아무런 문제가 없습니다 (적어도 잘못된 형식을 지정하는 것 외). – user1686149