I have my program that displays a message and in the same message the user must enter a code. I'm trying to do the validation if he typed something or not, for that I use the code:
AlertDialog.Builder alert = new AlertDialog.Builder(context);
alert.setTitle("Código final"); //Set Alert dialog title here
alert.setMessage("Insira o código fornecido pela Nobre de la Torre:"); //Message here
// Set an EditText view to get user input
final EditText input = new EditText(context);
alert.setView(input);
alert.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
//Ações do botão da mensagem
String srt = String.valueOf(input.getEditableText());
if(srt!=""){ //ESSE É O IF QUE ESTÁ COM ERRO
Toast.makeText(context,srt,Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(context,"Campo vazio!",Toast.LENGTH_LONG).show();
}
String hexNumber = srt;
int decimal = Integer.parseInt(hexNumber, 16);
System.out.println("Hex value is " + decimal);
[COntinua...]
Even with the variable String srt
being ""
it sees as different from ""
and executes the code below it
String srt = String.valueOf(input.getEditableText());
if(srt!=""){
Toast.makeText(context,srt,Toast.LENGTH_LONG).show();
}
Being that he should run else
:
else {
Toast.makeText(context,"Campo vazio!",Toast.LENGTH_LONG).show();}