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是您在上面看到的代码。在程序的其他地方,我使用几乎完全相同的代码,对话框显示正常。只有在这种特定情况下,对话框才会显示。 –