简体   繁体   中英

Android Studio how do I check email address and password before starting a new activity

Making a prototype app that requires an email address & password I am quite new to java, I have tried the following method but the new activity does not open. If anyone has any helpful hints/tips it would be appreciated :)

 public class LogonScreen extends ActionBarActivity { private Button SignInButton; private EditText Emailbox,Passwordbox; private CheckBox RememberMe; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_logon_screen); SignInButton = (Button) findViewById(R.id.SignInButton); Emailbox = (EditText) findViewById(R.id.EmailBox); Passwordbox = (EditText) findViewById(R.id.PasswordBox); RememberMe = (CheckBox) findViewById(R.id.RememberMeBox); } 
public void SignInButtonOnClick(View View){
    if(((Emailbox.getText().toString()).equals(R.string.EmailAd))&&((Passwordbox.getText().toString()).equals(R.string.password))){
        Intent i = new Intent(this, MenuPage.class);
        startActivity(i);
    }
}

Do it like this, it should work.

if(((Emailbox.getText().toString()).equals(getString(R.string.EmailAd)))&&((Passwordbox.getText().toString()).equals(getString(R.string.password)))) 

You're Emailbox.getText().toString()).equals(R.string.EmailAd) doing like this which is not correct because R.string.EmailAd will give you unique ID assigned to this string so this condition will never true.

To get the string which is in the resources you need to call like getString(resource_name) and try to follow java camel cases naming convention.

@Sajad, mentioned you need to apply click listener also on the signInButton button

SignInButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {

            //your intent
        }

    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM