moony
moony

Reputation: 434

edittext change hint text programmatically

I have an EditText where I set a hint with

editText.setHint("Hint 1");

This works because the EditText was empty before. But now I want to change the hint so that "Hint2" is shown in the EditText.

Unfortunatelly

editText.setHint("Hint2");

doesn't work because the EditText is not empty this time.

Does anyone know a solution?

Upvotes: 0

Views: 8605

Answers (2)

andredami
andredami

Reputation: 71

The hint change is correctly achieved with

editText.setHint("Your hint");

But it will get displayed only when the EditText's text gets cleared with:

editText.getText().clear();

This is consistent with the purpose of a hint, i.e. give the user a hint on what to write in a text field (if already filled there's no purpose of showing an hint!)

Upvotes: 3

Warwicky
Warwicky

Reputation: 281

Have you tried setting editText.setText(null); and set the hint? After setting hint you can set the text again.

Upvotes: 4

Related Questions