0

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?

ligi
  • 39,001
  • 44
  • 144
  • 244
moony
  • 424
  • 1
  • 7
  • 20
  • 1
    This is illogical. Hints only show if the edit text is empty. Are you asking how to clear the text box? If you delete the text from it, does it say `"Hint2"`? – IAmGroot Oct 07 '14 at 15:29
  • Yes, as Doomskinght pointed out, it is very unclear what your concern is. Doesn't it re-set the hint anyways? – TehCoder Oct 07 '14 at 15:36

2 Answers2

4

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

Warwicky
  • 281
  • 4
  • 9
  • This has no effect on the EditText's hint String. It doesn't matter if there is currently text displayed or not. – TehCoder Oct 07 '14 at 15:42
3

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!)

andredami
  • 71
  • 3