buttons.get(2).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
if(buttons.get(2).getText().toString().equalsIgnoreCase(getResources().getString(R.string.show))){
editTexts.get(1).setInputType(InputType.TYPE_CLASS_TEXT);
editTexts.get(1).setSelection(editTexts.get(1).getText().length());
buttons.get(2).setText(getResources().getString(R.string.hide));
}else{
editTexts.get(1).setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
//editTexts.get(1).setTransformationMethod(PasswordTransformationMethod.getInstance());
editTexts.get(1).setSelection(editTexts.get(1).getText().length());
buttons.get(2).setText(getResources().getString(R.string.show));
}
}
});
Explanations:- I have a button with default text as show. After onclick event on it checking if button's text is show. If it is show then changing the input type,adjusting the cursor position and setting new text as hide in it.
When it is hide... doing reverse i.e. hiding the password,adjusting the cursor and setting the text as show. And that's it. It is working like a charm.