I am making a program that requires a password for the settings page. Currently how I’m going about that is by having an alert pop up with a text field and a request for a password. When the correct password is entered (currently hardcoded as “test” but that will be changed) it should start the settings activity, with an incorrect password resulting in an alert saying “incorrect”.
At the moment, regardless of right or wrong password it just closes the alert, no message or anything.
I’m learning as I go so I’m sure I’ve severely mauled the code, any suggestions?
public void Settings(View view) {
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Main User Only");
alert.setMessage("Please enter password");
// Set an EditText view to get user input
final EditText input = new EditText(this);
alert.setView(input);
alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String value = input.getText().toString();
if (value == "test")
{Intent settings = new Intent(Bootscreen.this, ItemListActivity.class);
startActivity(settings);}
else
if (!(value == "test")) { alert.setMessage("Incorrect");}}
});
alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
// Canceled.
}
});
alert.show();
}
use
instead of
for comparing Strings