您的位置:首页 > 移动开发 > Android开发

AlertDialog,当点击按钮时,能够根据界面上输入的数据,弹出对话框,显示界面中输入的相关信息

2014-05-20 07:14 901 查看
我的代码采用分离监听器的模式,即不在 setOnclickListener 中 new OnClickListener(). 

public class MainActivity extends Activity  implements View.OnClickListener{
protected void onCreate(Bundle savedInstanceState){
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(this);
}
}


@Override
public void onClick(View v) {
// TODO Auto-generated method stub
final EditText etname = (EditText)findViewById(R.id.name);
EditText etphone = (EditText)findViewById(R.id.phoneNum);
EditText etpassword = (EditText)findViewById(R.id.password);
RadioGroup group = (RadioGroup)findViewById(R.id.radiogroup1);
RadioButton select = (RadioButton)findViewById(group.getCheckedRadioButtonId());
String line = "你的姓名:" + etname.getText().toString() +
"\n你的电话:" + etphone.getText().toString() +
"\n你的密码:" + etpassword.getText().toString() +
"\n你的选择:" + select.getText().toString();
AlertDialog.Builder dlg = new AlertDialog.Builder(MainActivity.this);
dlg.setIcon(android.R.drawable.btn_dialog);
dlg.setTitle("欢迎你的注册");
dlg.setMessage(line);
dlg.setPositiveButton("确定", new DialogInterface.OnClickListener() {

@Override
public void onClick(DialogInterface dialog, int which) {

etname.setText("你已点过注册啦!");
}
});
dlg.setNegativeButton("退出", null);
dlg.create().show();
}
}





如果以上论述有错误或不足之处,欢迎大家指出,希望我的文章能帮助到大家。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  android AlertDialog
相关文章推荐