Compare Textview And Edittext Values
I am trying to compare EditText value with TextView, but always getting 'Does not match !' Is this the wrong way to compare two values ? For an example : I have stored win in Text
Solution 1:
Add this line in your onClick
method of the Buttton
strPassword = editPassword.getText().toString();
Present your edittext value is empty string means ""
Solution 2:
Use
strPassword = editPassword.getText().toString();
line inside of your onClick() event
In your case the edit text value is always to be ""
Solution 3:
EditText editPassword;
String strPassword;
TextView lblPassword;
String password;
String strMatch;
@OverridepublicvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.single_list_item);
editPassword = (EditText) findViewById(R.id.editPassword);
// getting intent dataIntentin = getIntent();
password = in.getStringExtra(TAG_PASSWORD);
lblPassword = (TextView) findViewById(R.id.password_label);
lblPassword.setText(password);
btnSubmit = (Button) findViewById(R.id.btnSubmit);
btnSubmit.setOnClickListener(newOnClickListener() {
@OverridepublicvoidonClick(View arg0) {
// TODO Auto-generated method stub
strPassword = editPassword.getText().toString();
strMatch= lblPassword.getText().toString();
if(strPassword.equals(strMatch))
{
Toast.makeText(getApplicationContext(), "Match !",
Toast.LENGTH_LONG).show();
editPassword.setText(null);
}
else
{
Toast.makeText(getApplicationContext(), "Does not match !",
Toast.LENGTH_LONG).show();
}
}
});
}
Solution 4:
Think about the ORDER of your lines. You first assign ONCE at the beginning something to strPassword and strMatch, and then you change the underlying controls (maybe even by editing something in your GUI), but your onClick() method still compares the values you initially stored in strPassword and strMatch.
Try replacing
if(strPassword.equals(strMatch))
with
if(editPassword.getText().equals(lblPassword.getText()))
(or append toString()
to each, I don't remember if toString()
is needed or not.
Solution 5:
Try following code
if(strPassword.trim().equals(strMatch.trim()))
Post a Comment for "Compare Textview And Edittext Values"