所以我有一些代碼設置onClickListener的按鈕,似乎不適用於屏幕尺寸小於4英寸,但只適用於特定按鈕的設備。我不知道爲什麼,因爲它似乎不是OS級版本的影響,但只是屏幕大小。OnclickListener無法在小屏幕尺寸上工作?
我在onclick方法中記錄代碼,顯示除new_game按鈕之外的所有按鈕註冊和正確觸發。任何意見,爲什麼這可能會發生,將不勝感激。從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);
}
}
}
原來我有一種被放置在按鍵上的小規模的低密度屏幕的無人居住的滾動視圖。上面的代碼沒有錯(至少在格式不好的情況下)。 – user1686149