• 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?

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.
 
  • Like
Reactions: alostpacket

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones