public class PopUpDialog extends Dialog {
Context context;
private View customView;
public PopUpDialog(Context context) {
super(context);
this.context = context;
// TODO Auto-generated constructor stub
}
public PopUpDialog(Context context, int theme){
super(context, theme);
this.context = context;
LayoutInflater inflater= LayoutInflater.from(context);
customView = inflater.inflate(R.layout.mydialog, null);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
this.setContentView(customView);
}
@Override
public View findViewById(int id) {
// TODO Auto-generated method stub
return super.findViewById(id);
}
public View getCustomView() {
return customView;
}
}
customView = inflater.inflate(R.layout.mydialog, null);通过此语句获取view“指针”(借用C的术语),在新的Activity中实现调用自定义对话框中的控件。
PopUpDialog newDialog = new PopUpDialog(MsgReView.this, R.style.MyDialog);
newDialog.setCanceledOnTouchOutside(true);
View view = newDialog.getCustomView();
TextView text1 = (TextView)view.findViewById(R.id.textViewTotal);
text1.setText("调查人数:5");
本文介绍如何在新的Activity中实现调用自定义对话框,并展示如何通过Java代码获取并操作对话框中的视图元素。通过实例演示了创建自定义对话框的基本步骤,包括设置布局、创建对话框对象、设置取消外触关闭功能以及访问对话框内部的自定义视图。
412

被折叠的 条评论
为什么被折叠?



