志在指尖
用双手敲打未来

Android开发笔记

1.运用AlertDialog.Builder 对话框自定义view,并经过setview设置Android
AlertDialog.Builder dlgAlert;
dlgAlert = new AlertDialog.Builder(this);
LayoutInflater inflater = getLayoutInflater();
dlgAlert.setTitle(“用户协议”); //dlgAlert.setMessage(R.string.agreement); View checkView=inflater.inflate(R.layout.agreedialogview,null);
dlgAlert.setView(checkView);
CheckBox agreeCheck=(CheckBox)checkView.findViewById(R.id.checkBox_agree);;
dlgAlert.setPositiveButton(“确认”, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close current activity if (agreeCheck.isChecked()) {
init();
} else {
finish();
System.exit(0);
}
}
}).create();
dlgAlert.setNeutralButton(“退出”, new DialogInterface.OnClickListener() {
@Override public void onClick(DialogInterface dialog, int id) { // if this button is clicked, close current activity finish();
System.exit(0);
}
}).create();
dlgAlert.show();
这儿要想在对话框按钮的监听事情中调用xml布局里面的控件,不能直接findViewById,需求这样写
View checkView=inflater.inflate(R.layout.agreedialogview,null);
dlgAlert.setView(checkView);
CheckBox agreeCheck=(CheckBox)checkView.findViewById(R.id.checkBox_agree);;
对话框.show()函数之后才能够调用,

未经允许不得转载:IT技术网站 » Android开发笔记
分享到: 更多 (0)

评论 抢沙发

评论前必须登录!

 

志在指尖 用双手敲打未来

登录/注册IT技术大全

热门IT技术

C#基础入门   SQL server数据库   系统SEO学习教程   WordPress小技巧   WordPress插件   脚本与源码下载