1. Download our Official Android App: Forums for Android!

Apps Dynamically Change Hint Text In EditText Field?

Discussion in 'Android Development' started by Laxidasical, Sep 8, 2011.

  1. Laxidasical

    Laxidasical Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    25
    Joined:
    Aug 25, 2011

    Aug 25, 2011
    25
    3
    16
    Chicago
    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 (Text):
    1. 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 (Text):
    1. EditText text = (EditText)findViewById(R.id.myEditTextField);
    2. 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.
     

    Advertisement

    alostpacket likes this.
  2. alostpacket

    alostpacket Over Macho Grande?
    Rank:
    None
    Points:
    513
    Posts:
    7,971
    Joined:
    Nov 29, 2009

    Nov 29, 2009
    7,971
    3,604
    513
    Android App Developer
    NY
    thanks for posting back the solution :D
     
  3. Laxidasical

    Laxidasical Newbie
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    25
    Joined:
    Aug 25, 2011

    Aug 25, 2011
    25
    3
    16
    Chicago
    No problem!
     

Share This Page

Loading...