1
所以我想問一個用戶他們的名字,然後繼續構建一個活動。大多數活動都是動態填充的,所以看起來應該很容易。出於某種原因,雖然沒有出現對話框。我試過所有的東西,唯一能想到的是:也許它不喜歡在onCreate方法中?它似乎並不是這個問題,儘管它實際上是在onCreate中調用的最後一個方法。檢查出來,讓我知道你所看到的:AlertDialog不會顯示在onCreate方法
onCreate方法:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initializeHotels();
FIRST_TURN = true;
clearOldBoard();
setContentView(R.layout.activity_game_board);
setUpBoardGUI();
setOnPlayerSetUpEventListener(new onPlayerSetUpEventListener() {
@Override
public void onPlayerSetUp(){
prepForFirstTurn();
}
});
startGameDialog();
}
而startGameDialog方法:
public void startGameDialog(){
Context context = getApplicationContext();
ContextThemeWrapper ctw = new ContextThemeWrapper(context, R.style.AppBaseTheme);
AlertDialog.Builder startGameDialog = new AlertDialog.Builder(ctw);
startGameDialog.setTitle(getResources().getString(R.string.whats_your_name));
LinearLayout dialogLayout = new LinearLayout(context);
final EditText newName = new EditText(context);
newName.setText("");
Button submit = new Button(context);
OnClickListener onClick = new OnClickListener() {
@Override
public void onClick(View v) {
GameBoardActivity.NAME = newName.toString();
setUpPlayers();
}
};
submit.setOnClickListener(onClick);
dialogLayout.addView(newName);
dialogLayout.addView(submit);
startGameDialog.setView(dialogLayout);
Dialog dialog = startGameDialog.create();
dialog.show();
dialog.setCancelable(false);
}
抱歉。這是一個「不行」。特別是因爲我在程序中的其他對話框中使用了相同的代碼設計,並且它完美無瑕地執行。 (無論如何嘗試,它不起作用)。 –
@JRadtheBad它正在工作??但它不適用於你當前的活動? –
不會顯示的AlertDialog是您在上面看到的代碼。在程序的其他地方,我使用幾乎完全相同的代碼,對話框顯示正常。只有在這種特定情況下,對話框纔會顯示。 –