I am trying to create a basic create account system (its my first day using android studio so dont judge too harshly) everytime i test the program it simply defaults straight to else even when the two passwords are vastly different. Thank you all very much for your help in advance.
public class CreateAccount extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_account);
Button Submit_btn = (Button) findViewById(R.id.Submit_btn);
final EditText Username_txt = (EditText)findViewById(R.id.Username_txt);
final EditText Email_txt = (EditText)findViewById(R.id.Email_txt);
final EditText Password_txt = (EditText)findViewById(R.id.Password_txt);
final EditText VerifyPassword_txt = (EditText)findViewById(R.id.VerifyPassword_txt);
final TextView Error_txt = (TextView)findViewById(R.id.Error_txt);
final String Username_string = Username_txt.getText().toString();
final String Email_string = Email_txt.getText().toString();
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
}
You should add trim()
Returns a string whose value is this string, with any leading and
trailing whitespace removed.
Submit_btn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
final String Password_string = Password_txt.getText().toString().trim();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString().trim();
if (!Password_string.equals(VerifyPassword_string))
{
Error_txt.setText("Passwords must be matching");
} else
{
Error_txt.setText("No Error");
}
}
});
change your onClick method to retrieve the values
public void onClick(View view) {
Password_string = Password_txt.getText().toString();
VerifyPassword_string = VerifyPassword_txt.getText().toString();
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
note
Also try to use java standard naming conventions
e.g.
String passwordString = "";
You hardcode the retrieved values from input widgets during the initialization of the Activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
...
final String Username_string = Username_txt.getText().toString();
final String Email_string = Email_txt.getText().toString();
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string =
VerifyPassword_txt.getText().toString();
...
}
You have the issue for password inputs, but you would have the same problem for email and user inputs.
You should get all of them dynamically.
For example for password inputs:
public void onClick(View view) {
if (!Password_txt.getText().toString().equals
(VerifyPassword_txt.getText().toString())) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
You are trying to get the values of your EditText at the time of onCreate it self at which time they won't have any values in them as you might be typing them only after screen is open. So you should do this calculation only on your onclick -
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
So understand the activity Lifecycle here. onCreate is called to setup your View as the first method to your Activity. At that time your view doesn't have any user filled data in it. Once the view is populated and you see the UI, then the user interacts with it. So any computation that you need to do after user input, has to be action based(in this case your btn click) and hence try to get the data always at the time of action.
try this
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
I have made some changes try it now
final String Username_string = Username_txt.getText().toString();
final String Email_string = Email_txt.getText().toString();
//final String Password_string = Password_txt.getText().toString();
//final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String passwordStr= Password_txt.getText().toString();
String passwordConfirmStr=VerifyPassword_txt.getText().toString();
if (!passwordStr.equals(passwordConfirmStr)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
});
Related
I am trying to make a app that has a switch a button and a text and if you turn the switch on and press the button; the number displayed on the text will be added by 1. But if the switch is turned off the number will be subtracted by 1.
but when i run my app and press the button, the app crashes...
i do not have much experience at programming and i do not know what im doing wrong. and i have only tried this code.
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final TextView text = (TextView)findViewById(R.id.textView);
final Button button = (Button)findViewById(R.id.button);
Switch mySwitch = (Switch)findViewById(R.id.mySwitch);
mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked== true){
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text_string = text.getText().toString();
int text_int = Integer.parseInt(text_string);
text_int++;
text.setText(text_int);
}
});
}
if (isChecked == false) {
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text_string = text.getText().toString();
int text_int = Integer.parseInt(text_string);
text_int++;
text.setText(text_int);
}
});
}
}
});
}
}
so this should behave as i described earlier but it doesn't.
Your app crashes because you are trying to set an int to a textview.setText()and when you pass an int to this method it expects it to be a resource id and which could not be found in your case that's why it will throw ResourceNotFoundException and crashes.
You should set text as following:
text.setText(String.valueOf(text_int));
You’re nesting listeners but that logic doesn’t work sequentially. You should declare your listeners separately. I suggest you create a boolean that holds the state of the switch and one button listener. Within the listener check if switch is enabled then run your calculations and do the same if the switch is disabled.
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(mySwitch.isChecked(){
String text_string = text.getText().toString();
int text_int = Integer.parseInt(text_string);
text_int++;
text.setText(String.valueOf(text_int));
} else {
String text_string = text.getText().toString();
int text_int = Integer.parseInt(text_string);
text_int++;
text.setText(String.valueOf(text_int));
}
}
});
You don't need a listener for the Switch, but only 1 listener for the Button:
final TextView text = (TextView)findViewById(R.id.textView);
final Button button = (Button)findViewById(R.id.button);
final Switch mySwitch = (Switch)findViewById(R.id.mySwitch);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String text_string = text.getText().toString();
int text_int = 0;
try {
text_int = Integer.parseInt(text_string);
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (mySwitch.isChecked())
text_int++;
else
text_int--;
text.setText("" + text_int);
}
});
Every time you click the Button, in its listener the value in the TextView is increased or decreased depending on whether the Switch is checked or not.
I'm rarely ask on here, so first of all I'm sorry if my question is readable or not allowed here. So what I'm trying to do here is passing the username from LoginActivity into the player1 variable at HomeActivity . here's the code for the HomeActivity.java class
public class HomeActivity extends Activity {
TextView NameTxt;
TextView CoinTxt;
TextView GemTxt;
String p1name = player1.getName();
int p1coin = player1.getCoins();
int p1gem = player1.getGems();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);
//////TV declare///////
NameTxt = (TextView)findViewById(R.id.playerName);
CoinTxt = (TextView)findViewById(R.id.cointxt);
GemTxt = (TextView)findViewById(R.id.gemtxt);
NameTxt.setText(p1name);
CoinTxt.setText("Coin: " +p1coin);
GemTxt.setText("Gem: " +p1gem);
}
}
And this is LoginActivity.class
public class LoginActivity extends Activity {
EditText edit1;
EditText edit2;
EditText edit3;
Button registerBtn;
Button loginBtn;
DatabaseHelper myDb;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Set fullscreen and no title//////////
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
///////////////////////////////////////
setContentView(R.layout.login_screen);
edit1 = (EditText)findViewById(R.id.editpname);
edit2 = (EditText)findViewById(R.id.editpemail);
edit3 = (EditText)findViewById(R.id.editppw);
registerBtn = (Button)findViewById(R.id.registerbtn);
loginBtn = (Button)findViewById(R.id.loginbtn);
myDb = new DatabaseHelper(this);
loginBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (validate()) {
String Email = edit2.getText().toString();
String Password = edit3.getText().toString();
User currentUser = myDb.Authenticate(new User(null, null, Email, Password));
if (currentUser != null) {
System.out.println("Successfull");
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
startActivity(intent);
finish();
} else {
System.out.println("Unsuccessfull");
}
}
}
});
registerBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (validate()) {
String UserName = edit1.getText().toString();
String Email = edit2.getText().toString();
String Password = edit3.getText().toString();
if (!myDb.isEmailExists(Email)) {
myDb.addUser(player1);
public User player1 = new User(null, UserName, Email, Password);
}
}
}
});
}
public boolean validate() {
boolean valid = false;
String Email = edit2.getText().toString();
String Password = edit3.getText().toString();
if (!android.util.Patterns.EMAIL_ADDRESS.matcher(Email).matches()) {
valid = false;
edit2.setError("Please enter valid email!");
} else {
valid = true;
edit2.setError(null);
}
if (Password.isEmpty()) {
valid = false;
edit3.setError("Please enter valid password!");
} else {
if (Password.length() > 5) {
valid = true;
edit3.setError(null);
} else {
valid = false;
edit3.setError("Password is to short!");
}
}
return valid;
}
}
And I also have simple User.java class
String id;
String userName;
String email;
String password;
int coins;
int gems;
public User(String id, String userName, String email, String password) {
this.id = id;
this.email = email;
//And so on. Don't mind this
}
public String getName() {
return this.userName;
}
public int getCoins() {
return this.coins;
}
public int getGems() {
return this.gems;
}
And I write the short code , for the sake of readability.
I get an error on
myDb.addUser(player1);
And the one below it.
I'm just trying to make so that the player name equals to the value of Username on the database . and also the coins and gems too. Can you guys help me to get the idea how to pass the value? It tooks me whole 3days to figure a way to fix this. And it just blew my brain. So maybe you guys can help me
Ignoring the database stuff and assuming that LoginActivity is started from another activity (MainActivity) then you could adapt the following which passes the Username and UserId (ample to then get any additional data in the HomeActivity from the database).
So this when it starts immediately invokes the LoginActivity.
Clicking Login (mimics getting user and id from db) starts the HomeActivity passing the Username and userid via Intent Extras.
The HomeActivity displays the username and userid, and additionally a DONE button.
Clicking the DONE button returns back through the stack (skippng LoginActivity as that was finished) to the MainActivity which changes the TextView from Hello World to Welcome Back (not that you'd ever see Hello World).
MainActivity.java :-
public class MainActivity extends AppCompatActivity {
TextView mMessage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMessage = this.findViewById(R.id.message);
// Immediately start Login Activity
Intent i = new Intent(MainActivity.this,LoginActivity.class);
startActivity(i);
}
#Override
protected void onResume() {
super.onResume();
mMessage.setText("Welcome back");
}
}
LoginActivity.java :-
public class LoginActivity extends AppCompatActivity {
public static final String INTENTKEY_USERNAME = "IK_USERNAME";
public static final String INTENTKEY_USERID = "IK_USERID";
Button mloginbtn;
Context mContext;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
mContext = this;
mloginbtn = this.findViewById(R.id.loginbtn);
mloginbtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent i = new Intent(mContext,HomeActivity.class);
i.putExtra(INTENTKEY_USERNAME,"Fred");
i.putExtra(INTENTKEY_USERID,99L);
startActivity(i);
finish();
}
});
}
}
HomeActivity.java
public class HomeActivity extends AppCompatActivity {
TextView mUsername, muserid;
Button mDone;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
mUsername = this.findViewById(R.id.username);
muserid = this.findViewById(R.id.userid);
mDone = this.findViewById(R.id.done);
mDone.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
finish();
}
});
Intent i = this.getIntent();
mUsername.setText(i.getStringExtra(LoginActivity.INTENTKEY_USERNAME));
muserid.setText(String.valueOf(i.getLongExtra(LoginActivity.INTENTKEY_USERID,0)));
}
}
I'd do the following:
...
Intent intent = new Intent(getApplicationContext(),HomeActivity.class);
intent.putExtra("username", Bob)
startActivity(intent);
finish();
...
and then in home have:
Intent intent = getIntent();
String easyPuzzle = intent.getExtras().getString("username");
I am trying to create a basic create account system (its my first day using android studio so dont judge too harshly) everytime i test the program it simply defaults straight to else even when the two passwords are vastly different. Thank you all very much for your help in advance.
public class CreateAccount extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_account);
Button Submit_btn = (Button) findViewById(R.id.Submit_btn);
final EditText Username_txt = (EditText)findViewById(R.id.Username_txt);
final EditText Email_txt = (EditText)findViewById(R.id.Email_txt);
final EditText Password_txt = (EditText)findViewById(R.id.Password_txt);
final EditText VerifyPassword_txt = (EditText)findViewById(R.id.VerifyPassword_txt);
final TextView Error_txt = (TextView)findViewById(R.id.Error_txt);
final String Username_string = Username_txt.getText().toString();
final String Email_string = Email_txt.getText().toString();
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
}
You should add trim()
Returns a string whose value is this string, with any leading and
trailing whitespace removed.
Submit_btn.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
final String Password_string = Password_txt.getText().toString().trim();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString().trim();
if (!Password_string.equals(VerifyPassword_string))
{
Error_txt.setText("Passwords must be matching");
} else
{
Error_txt.setText("No Error");
}
}
});
change your onClick method to retrieve the values
public void onClick(View view) {
Password_string = Password_txt.getText().toString();
VerifyPassword_string = VerifyPassword_txt.getText().toString();
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
note
Also try to use java standard naming conventions
e.g.
String passwordString = "";
You hardcode the retrieved values from input widgets during the initialization of the Activity :
#Override
protected void onCreate(Bundle savedInstanceState) {
...
final String Username_string = Username_txt.getText().toString();
final String Email_string = Email_txt.getText().toString();
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string =
VerifyPassword_txt.getText().toString();
...
}
You have the issue for password inputs, but you would have the same problem for email and user inputs.
You should get all of them dynamically.
For example for password inputs:
public void onClick(View view) {
if (!Password_txt.getText().toString().equals
(VerifyPassword_txt.getText().toString())) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
You are trying to get the values of your EditText at the time of onCreate it self at which time they won't have any values in them as you might be typing them only after screen is open. So you should do this calculation only on your onclick -
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
So understand the activity Lifecycle here. onCreate is called to setup your View as the first method to your Activity. At that time your view doesn't have any user filled data in it. Once the view is populated and you see the UI, then the user interacts with it. So any computation that you need to do after user input, has to be action based(in this case your btn click) and hence try to get the data always at the time of action.
try this
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
final String Password_string = Password_txt.getText().toString();
final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
if (!Password_string.equals(VerifyPassword_string)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
I have made some changes try it now
final String Username_string = Username_txt.getText().toString();
final String Email_string = Email_txt.getText().toString();
//final String Password_string = Password_txt.getText().toString();
//final String VerifyPassword_string = VerifyPassword_txt.getText().toString();
Submit_btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
String passwordStr= Password_txt.getText().toString();
String passwordConfirmStr=VerifyPassword_txt.getText().toString();
if (!passwordStr.equals(passwordConfirmStr)) {
Error_txt.setText("Passwords must be matching");
} else {
Error_txt.setText("No Error");
}
}
});
I am developing a simple app that retrieves the location of a place using google place picker API but i am unable to retrieve the data and set it to a textView.Everything else works apart for retrieving the data.When overriding a method always use the #Overide annotation in order to ensure you override the method you intend to in order to avoid the below mistake
Below is an example of my code:
public class MainActivity extends AppCompatActivity {
private EditText name;
private EditText email;
private TextView date;
private TextView location;
private Button Submit,Select;
private String NAME; // stores name value
private String EMAIL; // stores email value
private String DATE; // stores date value
private DatePickerDialog.OnDateSetListener dateSetListener;
int PLACE_PICKER_REQUEST = 1;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText)findViewById(R.id.edtNameID);
email = (EditText)findViewById(R.id.edtEmailID);
NAME = name.getText().toString();
EMAIL = email.getText().toString();
location = (TextView)findViewById(R.id.locationtxt);
date = (TextView)findViewById(R.id.txtSelectDate);
date.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
java.util.Calendar calendar = java.util.Calendar.getInstance();
int month = calendar.get(java.util.Calendar.MONTH);
int year = calendar.get(java.util.Calendar.YEAR);
int day = calendar.get(java.util.Calendar.DAY_OF_MONTH);
month = month+1;
DatePickerDialog dialog = new DatePickerDialog(MainActivity.this,R.style.Theme_AppCompat_DayNight, dateSetListener,year,month,day);
dialog.show();
}
});
dateSetListener = new DatePickerDialog.OnDateSetListener() {
#Override
public void onDateSet(DatePicker datePicker, int year, int month, int day) {
String result = day +"/" +month +"/"+year;
date.setText(result);
}
};
DATE = date.getText().toString();
Select = (Button)findViewById(R.id.SelectLocationbtn);
Select.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
PlacePicker.IntentBuilder builder = new PlacePicker.IntentBuilder();
try {
Intent intent = builder.build(MainActivity.this);
startActivityForResult(intent,PLACE_PICKER_REQUEST);
} catch (GooglePlayServicesRepairableException e) {
e.printStackTrace();
} catch (GooglePlayServicesNotAvailableException e) {
e.printStackTrace();
}
}
});
Submit = (Button)findViewById(R.id.Submitbtn);
Submit.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
}
});
}
protected void OnActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
if(requestCode==PLACE_PICKER_REQUEST){
if(resultCode== RESULT_FIRST_USER){
Place place = PlacePicker.getPlace(data, MainActivity.this);
String name = String.format("Place: %s",place.getName());
location.setText(name);
}
}
}
}
The problem is the captial O in OnActivityResult();
It's a good idea to use the #Override annotation in order to ensure you're overriding the method you intend to:
#Override
protected void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode,resultCode,data);
if(requestCode==PLACE_PICKER_REQUEST){
if(resultCode== RESULT_FIRST_USER){
Place place = PlacePicker.getPlace(data, MainActivity.this);
String name = String.format("Place: %s",place.getName());
location.setText(name);
}
}
}
I'm trying to produce a password check before submitting my form, but I'm not getting the desired behavior. Basically no matter what the user inputs for either field, it will submit the new password from mConfirmPasswordField. What I want to have happen is that if the passwords do not match, hence if (!(mNewPassword.equals(mConfirmPassword)), then an alert dialog is displayed and nothing more. Based on the code below, this seems like it should be the case but it simply saves the new password to the user either way. What am I doing wrong here?
mNewPasswordField = (EditText)findViewById(R.id.newPassword);
mConfirmPasswordField = (EditText)findViewById(R.id.newPasswordAgain);
final String mNewPassword = mNewPasswordField.getText().toString();
final String mConfirmPassword = mConfirmPasswordField.getText().toString();
mNewPasswordField.setText(mNewPassword);
mConfirmPasswordField.setText(mConfirmPassword);
Button mButton = (Button) findViewById(R.id.submitPasswordChanges);
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (!(mNewPassword.equals(mConfirmPassword))) {
AlertDialog.Builder builder = new AlertDialog.Builder(ChangePasswordActivity.this);
builder.setMessage("Please check that you've entered and confirmed your new password!")
.setTitle("Error:")
.setPositiveButton(android.R.string.ok, null);
AlertDialog dialog = builder.create();
dialog.show();
} else {
setProgressBarIndeterminateVisibility(true);
//Update user
ParseUser user = ParseUser.getCurrentUser();
user.setPassword(mConfirmPasswordField.getText().toString());
user.saveInBackground(new SaveCallback() {
public void done(com.parse.ParseException e) {
// TODO Auto-generated method stub
LaunchPersonalGalleryIntent();
}
});
}
}
final String mNewPassword = mNewPasswordField.getText().toString();
final String mConfirmPassword = mConfirmPasswordField.getText().toString();
This will be executed when the EditText are still empty, so mNewPassword equals mConfirmPassword equals "".
The two String should be retrieved within the onClick:
..
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String mNewPassword = mNewPasswordField.getText().toString();
final String mConfirmPassword = mConfirmPasswordField.getText().toString();
if (!(mNewPassword.equals(mConfirmPassword))) {
..
I believe what's wrong is that you are not updating your fields: you should check for new values right when the user clicks the button, like:
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mNewPassword = mNewPasswordField.getText().toString();
mConfirmPassword = mConfirmPasswordField.getText().toString();
if (!(mNewPassword.equals(mConfirmPassword))) {
....
} else {
....
}
}
});
I should mention for others passing through, that you will also need to include the following fields, along with the password strings, within the onClick method.
..
mButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mNewPasswordField = (EditText)findViewById(R.id.newPassword);
mConfirmPasswordField = (EditText)findViewById(R.id.newPasswordAgain);
final String mNewPassword = mNewPasswordField.getText().toString();
final String mConfirmPassword = mConfirmPasswordField.getText().toString();
mConfirmPasswordField.setText(mConfirmPassword);
if (!(mNewPassword.equals(mConfirmPassword))) {
..