When I Read of a BD of mysql, I try compare a String (User and Pasw) enter for the user with the date of BD. But if i put == never said my is equal.
i have a Variable box:
package clases;
import bdMySQL.BDUsuarios;
public class Usuarios {
private String Usuario;
private String Password;
private String Rol;
public Usuarios( String i, String n, String rol ){
this.Usuario = i;
this.Password = n;
this.Rol = rol;
}
public String getUsuario() {
return Usuario;
}
public String getRol(String Usuario, String Password) {
if (Usuario == this.Usuario && Password == this.Password){
return this.Rol;
}else{
return "";
}
}
}
And The consult of BD is correct.
When I lunch my main program:
public class PruebaMySQLActivity extends Activity {
public List<Usuarios> Usuarios;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button btnConectar = (Button)findViewById(R.id.btnConectar);
final TextView txtMensaje = (TextView)findViewById(R.id.txtMensaje);
btnConectar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0)
{
Usuarios = BDUsuarios.getDatosUsuarios();
String rol = "";
String Usuario = "miuser";
String Pasw = "mipasw";
int i = 1;
while (i < Usuarios.size() && rol == ""){
//Toast t=Toast.makeText(getBaseContext(),String.valueOf(i) + " " + familias.get(i).getUsuario() + " " + familias.get(i).getPassword() + " " + familias.get(i).getrol2() , Toast.LENGTH_LONG);
//t.show();
rol = Usuarios.get(i).getRol(Usuario, Pasw);
i= i + 1;
}
txtMensaje.setText(rol);
}
});
}
}
The toast show me perfectly all data, but when I tried to do the "==" not found. And i tried to:
Usuario.equals(this.Usuario)
and not found.
Thanks for the help.