Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android add placeholder text to EditText

How can I add a placeholder text to EditText in the class that isn't in the XML?

I have the following EditText in my code which will be shown in alertdialog:

    final EditText name = new EditText(this); 
like image 719
Mona Avatar asked Nov 22 '11 02:11

Mona


People also ask

Can edit the text in the placeholder?

Change the prompt text in a placeholderIn slide master view, in the thumbnail pane, select the layout that you want to revise. In the main pane, on the layout, select the current prompt text (such as Click to edit text, and then type the text you want to use instead.

What is a place holder in Android Studio?

A Placeholder provides a virtual object which can position an existing object.

How do I use hint on Android?

To label an editable TextView or EditText , use android:hint to display a descriptive text label within the item when it's empty. If an app's user interface already provides a text label for the editable item, define android:labelFor on the labeling View to indicate which item the label describes.

What is placeholder in application?

A placeholder is used to show what needs to be filled in at a certain position.


1 Answers

Ah, ok. What you're looking for is setHint(int). Simply pass in a resource id of a string from your xml and you're good to go.

enter image description here

EDIT

And in XML, it's simply android:hint="someText"

like image 50
LuxuryMode Avatar answered Sep 20 '22 08:09

LuxuryMode