When button pressed want to visible the password otherwise it should be hidden or say dotted. I have Applied the following code but its not working. Any help would be appreciated.
button.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(button.isPressed()) {
upass.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
return true;
}
return true;
}
});
You have used
OnTouchListener
which gives youMotionEvent
's. Use them! No need to check the button is pressed again as long as you are pressing itMotionEvent
is there.To visible a password field with with the password :
inputType = TYPE_CLASS_TEXT | TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
When the button is pressed
MotionEvent.ACTION_UP
So you can visible the text. WhenMotionEvent.ACTION_DOWN
keep it as it was at the beginning.