Android 在一个Dialog里面,如何FindViewById找到自定义的CheckBox
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();
}
[解决办法]
//这里引用CheckBox,但报空指针错误
// cBox = (CheckBox) findViewById(R.id.agreement_cb);
这里默认的this 指针 指向的不是View
所以报错 恭喜楼主解决问题哦。。