I am trying to develop a login page but when a button is clicked it showing me username as ""
public class MainActivity extends AppCompatActivity {
public static final String userNameValue="abc";
public static final String passwordValue="abc";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
EditText editText1=(EditText)findViewById(R.id.userName);
final String valueUN= editText1.getText().toString();
EditText editText2=(EditText)findViewById(R.id.password);
final String valuePW=editText2.getText().toString();
Button loginButton=(Button)findViewById(R.id.button);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(valueUN==userNameValue && valuePW==passwordValue) {
Toast.makeText(MainActivity.this, "Login was Successfully", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Username or password is incorrect", Toast.LENGTH_SHORT).show();
}
}
});
}
}
when I tried to debug the code using debugger it is displaying valueUN and valuePW as "",why it is showing so? it should display what I enter.
It is not duplicate of question Get Value of a Edit Text field cause in that question person wanted to capture value entered in a edittext and mmy question is that edit text is not displaying a right value