Android 在一个Dialog里面,如何FindViewById找到自定义的CheckBox

Mars2639 2011-07-23 04:39:08
private Dialog buildDialog1(Context context){
LayoutInflater inflater = LayoutInflater.from(this);
final View textEntryView = inflater.inflate(R.layout.loading_dialog_agreement, null);
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setIcon(R.drawable.icon_default);
builder.setTitle(R.string.use_agreement);
builder.setView(textEntryView);
builder.setPositiveButton(R.string.dialog_ok,
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int whichButon) {
//setTitle("单击对话框上的确定按钮");

//这里引用CheckBox,但报空指针错误
// cBox = (CheckBox) findViewById(R.id.agreement_cb);
if(cBox.isChecked()){
mIntent = new Intent();
mIntent.setClass(LoadingActivity.this, MainActivity.class);
startActivity(mIntent);
}
else{
}
}
});

return builder.create();
}




...全文
723 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
red0197 2014-01-06
  • 打赏
  • 举报
回复
thanks
Mars2639 2011-07-27
  • 打赏
  • 举报
回复
- 恩,谢谢。。。
- 分我给2楼了!嘿嘿
ch_984326013 2011-07-23
  • 打赏
  • 举报
回复
恭喜LZ,问题解决了就好!呵呵
雨松MOMO 2011-07-23
  • 打赏
  • 举报
回复
//这里引用CheckBox,但报空指针错误
// cBox = (CheckBox) findViewById(R.id.agreement_cb);
这里默认的this 指针 指向的不是View
所以报错 恭喜楼主解决问题哦。。
Mars2639 2011-07-23
  • 打赏
  • 举报
回复
- 自己找到解决方法,结贴。
- dialog的contentview是通过setView()给的。
- contentView.findViewById()找到你的checkbox

80,351

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧