I have implemented activity with edittext and button:
After user entered a password and clicked a button, I’d like to verify the password and if it is correct open another activity. If the password is wrong I’d like to display an error message using AlertDialog.
Is it possible? How?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.enter);
//---load the SharedPreferences object---
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
String a = prefs.getString(PASSWORD, "pa");
System.out.println("saved Password" +a);
EditText et = (EditText)findViewById(R.id.txtName);
String theText = et.getText().toString();
System.out.println("entered Password"+theText);
//---get the SharedPreferences object---
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString(PASSWORD, theText );
//---save the values---
editor.commit();
Button data = (Button)findViewById(R.id.Ok);
data.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Enter.this,Data.class);
startActivity(i);
}
});
You can catch the password string into button click event.There,you can open a dialog depending on the correction of password.
Like: