Java – check user name and password in Android
•
Java
I have a username and password field, now I need to check it and redirect it to the next page of Android
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final EditText loginText = (EditText) findViewById(R.id.widget44);
final EditText loginPassword = (EditText) findViewById(R.id.widget47);
final Button button = (Button) findViewById(R.id.widget48);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent myIntent = null;
if(loginText.getText().equals("admin") &&
loginPassword.getText().equals("admin")) {
System.out.println("Entering");
myIntent = new Intent(view.getContext(),Page1.class);
} else {
}
startActivity(myIntent);
}
});
}
Now I'm hard coding to check these values, but it doesn't work for me Why? I usually check Java like this. Why doesn't it accept me in the same way in Android
Solution
I think this is because EditText #gettext () returns an editable object attempt
if(loginText.getText().toString().equals("admin") &&
loginPassword.getText().toString().equals("admin")) {
...
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
