例如
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(someView);
AlertDialog dialog = builder.create();
dialog.show();
... then later ...
dialog.setView(someOtherView);
代码执行没有错误,但对话框中的视图没有被替换。我做错了还是不可能?
例如
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(someView);
AlertDialog dialog = builder.create();
dialog.show();
... then later ...
dialog.setView(someOtherView);
代码执行没有错误,但对话框中的视图没有被替换。我做错了还是不可能?
我认为警报对话框构建器不会以传统方式构建警报对话框,以便与所有版本的 android 兼容,因此您需要更新内容视图。
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
AlertDialog alertDialog = builder.create();
alertDialog.show();
然后稍后
alertDialog.setContentView(newView);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setView(view);
AlertDialog alertDialog = builder.create();
alertDialog.show();
然后稍后
alertDialog.dismiss();
AlertDialog.Builder updatedBuilder = new AlertDialog.Builder(context);
updatedBuilder.setView(updatedView);
AlertDialog updatedAlertDialog = builder.create();
updatedAlertDialog.show();
不,这是不可能的。尝试关闭警报框并设置您的视图并再次显示它。