3
I have my program that displays a message and in that same message the user must enter a code. I’m trying to validate whether he typed something or not, so 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 ""
he sees as different from ""
and execute the code below it
String srt = String.valueOf(input.getEditableText());
if(srt!=""){
Toast.makeText(context,srt,Toast.LENGTH_LONG).show();
}
Since he should execute the else
:
else {
Toast.makeText(context,"Campo vazio!",Toast.LENGTH_LONG).show();}
http://answall.com/questions/3905/como-comparar-strings-em-java
– Piovezan