我正在尝试使用 alertDialog.Builder 在对话框中显示我的自定义视图,其中包含以下代码段。
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();
}
如果用户对该自定义视图的组件执行任何操作,我想更改/更新对话框的内容。因此,当用户触摸/点击自定义视图的任何组件时,我正在更新 popupView 并将更新的 popupView 传递给 showPopupView(查看popupView)再次。但视图未在对话框上更新。
我的要求类似于以下示例。
在对话框中显示用户名,密码文字输入字段和“确定”按钮的登录页面。
如果用户输入了错误的用户名/密码并按“确定”按钮,则应使用视图更新相同的对话框,该视图将显示错误消息textview 用户名& 密码文字输入字段和“确定”按钮应替换为同一对话框中的“再试一次”按钮。
< / LI>当用户按“再试一次”按钮时,上一个登录页面应显示在同一个对话框中。
我的意思是流量应该与相同活动的变化视图类似。 我想我已经提供了有关我的问题的充分信息。 请建议我解决我的问题。 在此先感谢。
答案 0 :(得分:0)
我能够管理并找到此问题的解决方案。刚删除 AlertDialog.Builder 并将 AlertDialog 更改为 Dialog 并在对话框中调用addContentView(view)而不是调用setView (查看) AlertDialog.Builder 。并在对话框上的contentview上添加和删除chaildviews。找到下面的代码段。
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();
}
}
如果任何其他人面临同样的问题,这可能会有所帮助。