Android 刷新对话框的内容
我需要更新一个自定义对话框的内容,每当该对话框准备好绘制时。我不确定是否可以直接刷新该对话框,或者是否需要先将其关闭并重新恢复?获取对话框正在使用的视图并[post]使其无效 而不是Android 刷新对话框的内容,android,Android,我需要更新一个自定义对话框的内容,每当该对话框准备好绘制时。我不确定是否可以直接刷新该对话框,或者是否需要先将其关闭并重新恢复?获取对话框正在使用的视图并[post]使其无效 而不是Dialog.setContentView(int) 做一些类似于: public class MyDialog { View v = null; public Dialog show(Context context) { Dialog d = new Dia
Dialog.setContentView(int)
做一些类似于:
public class MyDialog {
View v = null;
public Dialog show(Context context) {
Dialog d = new Dialog(context);
v = LayoutInflater.from(context).inflate(R.layout.resource, null);
d.setContentView(v);
return d.show();
}
public void update() {
v.invalidate();
}
}
您可以在
onPrepareDialog
中执行所有操作。每次显示对话框时都会调用它
void onPrepareDialog(final int id, final Dialog dialog) {
switch(id) {
case MY_DIALOG:
TextView txtView = (TextView)dialog.findViewById(R.id.mytext);
txtView.setText("My new text"):
....
}
}
是否要更新对话框中某个视图的某些值,或使用新的视图布局完全重画它?我看不出在什么情况下需要重画。你能帮我澄清一下吗?如果有人想要一个服务来更新对话框[ProgressBar Maybay?],那就是一个了。@AshishDwivedi你的解决方案是什么?好的,但是LayoutInflater只使用一个参数作为上下文。OP想在创建和显示is之后更新对话框。