I have an AlertDialog
with an EditText
inside it:
final EditText et = new EditText(getActivity());
AlertDialog.Builder myDialog = new AlertDialog.Builder(getActivity());
myDialog.setTitle("My Title").setView(et);
myDialog.setPositiveButton("Ok",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if(et.getText().toString() != ""){
//Do funny things
}
}
});
myDialog.setNegativeButton("Ok",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
My objective is do nothing if the EditText
is empty, with nothing i mean nothing. But there are 2 problems:
When click on
setPositiveButton
, the dialog is closed even if theonClick
method is empty.If
EditText
is empty i don't know which ASCII character should I match in the if condition. I mean:vNombre.getText().toString() == null; vNombre.getText().toString() == " "; vNombre.getText().toString() == "";
This 3 statements return false so I don't know with what I should compare et.getText().toString()
Is there any solution to problem 1 without add custom button to the view of the dialog?
Any ideas for problem 2?