I want my alert dialog box to trigger and stay showing an error message if the user leaves the name field empty and clicks ok but my dialogue box disappears even if the user does not fill anything and click ok.Here is my code. Please suggest me the corrections I need to make.
save2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final dbmanager db= new dbmanager(cgpa3.this);
final AlertDialog.Builder alert = new AlertDialog.Builder(cgpa3.this);
// alert.setTitle("Enter a name");
alert.setMessage("Enter student Name");
// Set an EditText view to get user input
final EditText input = new EditText(cgpa3.this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
if(value.isEmpty()){
Animation shake = AnimationUtils.loadAnimation(cgpa3.this, R.anim.shake);
input.startAnimation(shake);
input.setError("Please enter student name");
}
else
{db.addRecord1(value,textView39.getText(),textView40.getText(),no_of_sem);
}
}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
};
});