• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Dynamically Change Hint Text In EditText Field?

Laxidasical

Newbie
Is there a way to change the hint text used in EditText fields??? I've figured out how to alter the value, but not the hint text. I thought there would be something like this code below, but I can't find a function that does this:

Code:
findViewById(R.id.myEditTextField).[B][COLOR="Sienna"]setHint([/COLOR][/B]"New Hint Text"[B][COLOR="Sienna"])[/COLOR][/B];

Right now I'm using a workaround. For each text field that requires an alternate hint text, I created a second field with the alternate hint in place and then switch the visibility between the two depending on certain settings. While this works for the most part it's definitely not an elegant solution!


UPDATE:

I figured it out. The EditText id must be set to set to a variable and casted as EditText, then setHint() can be used on that variable. For example...

Code:
EditText text = (EditText)findViewById(R.id.myEditTextField);
text.setHint(R.string.myHintString);

Note I: Make sure to import android.widget.EditText.
Note II: I'm passing an id for a entry in strings.xml, but you can enter text directly.
 
Back
Top Bottom