0

I am creating a dialog box where there is a edit box I want to set the hint of editbox how can I do it.

please help me thank you

user1061793
  • 1,047
  • 8
  • 19
  • 27

3 Answers3

2

Every EditText is also TextView and the TextView defines a method setHint():

final void setHint(int resid)

Doesn't this work?

EDIT Btw by edit box you mean EditText right?

Boris Strandjev
  • 46,145
  • 15
  • 108
  • 135
1

I am not sure whether this works but might help you,

You could have initialized your Dialog with something like this,

         Dialog dialog = null;

And now to Initialize your EditText you should use something like this,

      edittext = (EditText) dialog. findViewById(R.id.editbox);

Now use the below method. It should do the trick,

            edittext.setHint("Hint");
Andro Selva
  • 53,910
  • 52
  • 193
  • 240
0

The same you can provide in the XML file also by adding :

android:hint="Text For Hint"

tag.

For dynamically adding it (in your code and not in XML), Boris & Androi have aldready mentioned it, so wont repeat it.

If you wont be changing once set, then I guess adding in XML is preferred rather than in code.

Tvd
  • 4,463
  • 18
  • 79
  • 125