我正在尝试显示一个警告对话框,如果单击检查帐户时缺少帐户信息.我在Eclipse中new AlertDialog.Builder(this)说错了the constructor AlertDialog.Builder(new View OnClickListener(){}) is undefined.如果我将它添加到活动的onCreate,代码工作正常.
checkButton.setOnClickListener(new OnClickListener() {
public void onClick(View Arg0){
String AccNum = null, Store = null;
final SharedPreferences settings = getSharedPreferences(CHECK_PREFERENCES, MODE_PRIVATE);
if (settings.contains("Account") == true){
AccNum = (settings.getString("Account", "default"));
Store = (settings.getString("Store", "default"));
}
if (AccNum.length() < 7) {
AlertDialog alert = new AlertDialog.Builder(this).create();
alert.setTitle("Account Information missing!");
alert.setMessage("Enter now? ");
alert.setButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
startActivity(new Intent(CheckOrder.this, GoToSetup.class));
}
});
alert.setButton2("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
return;
}
});
alert.show();
}
}
});