正在更新android对话框的ContentView,显示时不关闭
我试图使用带有以下代码片段的alertDialog.Builder在对话框中显示我的自定义视图正在更新android对话框的ContentView,显示时不关闭,android,view,dialog,android-alertdialog,Android,View,Dialog,Android Alertdialog,我试图使用带有以下代码片段的alertDialog.Builder在对话框中显示我的自定义视图 AlertDialog.Builder alertViewBuilder = null; AlertDialog alertViewDialog = null; public void showPopupView(View popupView) { if (alertViewBuilder == null) { alertViewBuilder = new AlertDialog.Build
AlertDialog.Builder alertViewBuilder = null;
AlertDialog alertViewDialog = null;
public void showPopupView(View popupView) {
if (alertViewBuilder == null) {
alertViewBuilder = new AlertDialog.Builder(ctContext);
}
alertViewBuilder.setView(popupView);
if (alertViewDialog == null)
alertViewDialog = alertViewBuilder.create();
if (!alertViewDialog.isShowing())
alertViewDialog.show();
}
private android.view.ViewGroup.LayoutParams alertLayoutParams = null;
private Dialog alertViewDialog = null;
private LinearLayout cvPopupView;
public void showPopupView(View popupView) {
if (cvPopupView == null)
cvPopupView = new LinearLayout(ctContext);
else
cvPopupView.removeAllViews();
cvPopupView.addView(popupView);
if (alertViewDialog == null) {
alertViewDialog = new Dialog(ctContext);
alertViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
if (alertLayoutParams == null) {
alertLayoutParams = new android.view.ViewGroup.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
}
if (!alertViewDialog.isShowing()) {
alertViewDialog.addContentView(cvPopupView, alertLayoutParams);
alertViewDialog.show();
}
}
如果用户对该自定义视图的组件执行任何操作,我希望更改/更新对话框的内容。因此,当用户触摸/单击自定义视图的任何组件时,我将更新popupView,并再次将更新后的popupView传递给showPopupView(view popupView)。但视图未在对话框中更新
我的要求与下面的示例类似
提前感谢。我能够管理并找到此问题的解决方案。刚刚删除了AlertDialog.Builder,将AlertDialog更改为Dialog,并在对话框中调用addContentView(视图),而不是在AlertDialog.Builder上调用setView(视图)。以及在对话框的contentview上添加和删除chaildviews。查找下面的代码片段
AlertDialog.Builder alertViewBuilder = null;
AlertDialog alertViewDialog = null;
public void showPopupView(View popupView) {
if (alertViewBuilder == null) {
alertViewBuilder = new AlertDialog.Builder(ctContext);
}
alertViewBuilder.setView(popupView);
if (alertViewDialog == null)
alertViewDialog = alertViewBuilder.create();
if (!alertViewDialog.isShowing())
alertViewDialog.show();
}
private android.view.ViewGroup.LayoutParams alertLayoutParams = null;
private Dialog alertViewDialog = null;
private LinearLayout cvPopupView;
public void showPopupView(View popupView) {
if (cvPopupView == null)
cvPopupView = new LinearLayout(ctContext);
else
cvPopupView.removeAllViews();
cvPopupView.addView(popupView);
if (alertViewDialog == null) {
alertViewDialog = new Dialog(ctContext);
alertViewDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
}
if (alertLayoutParams == null) {
alertLayoutParams = new android.view.ViewGroup.LayoutParams(
android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
}
if (!alertViewDialog.isShowing()) {
alertViewDialog.addContentView(cvPopupView, alertLayoutParams);
alertViewDialog.show();
}
}
如果有其他人面临同样的问题,这可能会有所帮助。您能解释一下“addContentView”的作用吗?API说它只是添加了它,但它不能被删除,我也不能得到这些视图。例如,如果我想从全屏进度条切换到普通的alertDialog样式,反之亦然,该怎么办?