AndroidProgress
AndroidProgress

Reputation: 1

Authentication Android

I want to create a static test in my authentication but when I click on button "Valider" nothing happen, instead when I remove the "if" condition and I click on "valider" button the next activity start. I think there is a problem when I put a condition for testing but I don't know what's it. Can you help ? thanks

public class TabAdmin extends Activity implements View.OnClickListener{
private EditText username;
private EditText password;

public String user_name;
public String pass_word;
private Button valider;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);


setContentView(R.layout.authen);

username = (EditText) findViewById(R.id.login);
password = (EditText) findViewById(R.id.pwd);

valider = (Button) findViewById(R.id.valider);
 valider.setOnClickListener((OnClickListener) this);
 }           
 public void onClick(View v) {              
     if (v == valider) {

    user_name = username.getText().toString();
     pass_word = password.getText().toString();
  if((user_name=="admin")&&(pass_word=="admin"))

     { 


        Intent goToNextActivity = new Intent(getApplicationContext(), MenuAdmin.class);
     startActivity(goToNextActivity);
     }           

 }

}

Upvotes: 0

Views: 315

Answers (3)

Ayudh
Ayudh

Reputation: 710

instead of

if((user_name=="admin")&&(pass_word=="admin"))

use

if((user_name.equals("admin"))&&(pass_word.equals("admin")))

I hope it can help u

Upvotes: 0

Jim Blackler
Jim Blackler

Reputation: 23179

For one thing the way you're comparing strings isn't right for Java. Try

if ("admin".equals(user_name) && "admin".equals(pass_word)) {

This isn't a great way of doing passwords though as anyone can read the strings out of the APK.

Upvotes: 1

pankajagarwal
pankajagarwal

Reputation: 13582

try using if (v.equals(valider)) instead of if (v == valider)

Upvotes: 1

Related Questions