标签:
step1 创建窗体
final AlertDialog dialog =new Builder(this).create();
step2 获取View
View viewDialog =View.inflate(this, R.layout.userinfo_dialog_edit, null); final EditText txtUserName=(EditText)viewDialog.findViewById(R.id.txtUserName); final EditText txtBirthday=(EditText)viewDialog.findViewById(R.id.txtBirthday); final EditText txtPhoneNumber=(EditText)viewDialog.findViewById(R.id.txtPhoneNumber); final EditText txtAddress=(EditText)viewDialog.findViewById(R.id.txtAddress); txtUserName.setText(userDto.getUserName()); txtBirthday.setText(userDto.getBirthday()); txtPhoneNumber.setText(userDto.getPhoneNumber()); txtAddress.setText(userDto.getAddress()); Button btnSave =(Button)viewDialog.findViewById(R.id.btnSave); Button btnClose =(Button)viewDialog.findViewById(R.id.btnClose); btnSave.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { UserInfoDto dto =new UserInfoDto(); dto.setUserName(txtUserName.getText().toString()); dto.setBirthday(txtBirthday.getText().toString()); dto.setPhoneNumber(txtPhoneNumber.getText().toString()); dto.setAddress(txtAddress.getText().toString()); InsertOneTest(dto); } }); btnClose.setOnClickListener(new OnClickListener(){ @Override public void onClick(View arg0) { dialog.dismiss(); } });
step3 show窗体
dialog.setView(viewDialog, 0, 0, 0, 0);
dialog.show();
标签:
原文地址:http://www.cnblogs.com/huangzhen22/p/4803487.html