我是一个初学者的android开发人员。 我有一个数据库表,计数以下列:_id,fistName,lastName和用户名设置为唯一。显示错误创建alertDialog()
当我在我的表中添加另一个人并且用户名已存在时,我创建了一个AlertDialog,但是此AlertDialog未出现。
这是我的源代码:
try {
personRepository.AddPerson(persons);
} catch (SQLiteConstraintException ex) {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
context);
alertDialogBuilder.setTitle("User already exist!");
alertDialogBuilder.setMessage("Choose another username!")
.setPositiveButton("Yes",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
dialog.cancel();
}
});
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
}
有人能帮助我吗?
发表您的addPerson的代码。 – 2013-04-22 16:30:08