The goal of my code is: when I type a secret username and password, then, press enter button, open a Activity3. otherwise, open Activity2. This is my code:
package edcomp.terraraimoveis;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TextInputLayout;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Principal extends Activity implements OnClickListener {
// UI references.
private AutoCompleteTextView userName;
private EditText mPasswordView;
private TextInputLayout nameLayout;
private TextInputLayout passLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_principal);
userName = (AutoCompleteTextView) findViewById(R.id.username);
//populateAutoComplete();
mPasswordView = (EditText) findViewById(R.id.password);
nameLayout = (TextInputLayout) findViewById(R.id.namelayout);
passLayout = (TextInputLayout) findViewById(R.id.passlayout);
Button entrarBtn = (Button) findViewById(R.id.entrarbtn);
entrarBtn.setOnClickListener(this);
}
@Override
public void onClick(View view) {
if(validateData() == true){
if(vipPass() == true){
Intent myintent = new Intent(Principal.this, AdicionarCredenciais.class);
Principal.this.startActivity(myintent);
}else {
Intent myintent = new Intent(Principal.this, DoisAtividade.class);
Principal.this.startActivity(myintent);
}
}
}
public boolean validateData(){
String nome = userName.getText().toString();
String pass = mPasswordView.getText().toString();
boolean result = true;
if(nome == null){
nameLayout.setError(getString(R.string.error_invalid_name));
result = false;
}else{
nameLayout.setErrorEnabled(false);
}
if(pass == null || pass.length() < 8){
passLayout.setError((getString(R.string.error_invalid_password)));
result = false;
}
return result;
}
public boolean vipPass() {
String nome = userName.getText().toString();
String pass = mPasswordView.getText().toString();
boolean vip_mode = false;
if (nome == "VIPUSER" && pass == "987654321") {
vip_mode = true;
}
return vip_mode;
}
}
I've added (activity android:name=".AdicionarCredenciais") and (activity android:name=".DoisAtividade") in manifest.xml. But, when I type the secret username and secret pass, then press Enter button, the next activity is not that I want.