Get text from TextView Android password

I hope that this has not been asked yet, since I could not find it. I am trying to get a username and password for an online service. I created a TextView username and TextView password. I can get the text from the TextView username without problems. However, I cannot get anything from the TextView password. The following is the XML:

<TextView android:id="@+id/user_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:layout_marginTop="8dp" android:text="@string/passcodeQuery" android:textAppearance="?android:attr/textAppearanceLarge" /> <EditText android:id="@+id/editText2" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginLeft="8dp" android:layout_marginRight="8dp" android:layout_marginTop="8dp" android:hint="@string/passwordHint" android:inputType="textPassword" /> 

The problem is that if I run the code

 TextView passField = (TextView)findViewById(R.id.user_password); 

then

 String toastMessage = "Password: " + passField.getText().toString(); 

No matter what I entered in the password field, the toast message gives me

 Password: Password 

Obviously, I will not fry the user password normally, I just do it now because I want to make sure that I read the input correctly. Unfortunately, this does not seem to be the case, as I cannot read the password field. How do you get around this? The tone of the application seems to be able to do this. Is there an easier way to get a password than what I'm doing?

+4
source share
5 answers

If you want Toast as "PassWord: YOUR EDITTEXT PICTURE", then use this.

 EditText passField = (EditText)findViewById(R.id.editText2); 

and then use:

 String toastMessage = "Password: " + passField.getText().toString(); 

Now write a message.

Enjoy. :)

+3
source

What about

 EditText passField = (EditText)findViewById(R.id.editText2); 

instead of "user_password"?

0
source

You should get text from EditText , not from TextView

 EditText passField = (EditText )findViewById(R.id.editText2); String toastMessage = "Password: " + passField.getText().toString(); 
0
source

Dude. You are trying to get the password from the TextView, which you must extract from the EditText.

 EditText password = (EditText)findViewById(R.id.editText2); 

Save it in String as

 String pwd = password.getText().toString(); 

And a toast for my own check

0
source

You can get value from EditText not from TextView. You can set not to receive.

  EditText passField = (EditText )findViewById(R.id.editText2); String toastMessage = "Password: " + passField.getText().toString().trim(); 
0
source

Source: https://habr.com/ru/post/1397164/


All Articles