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);
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.
A Placeholder provides a virtual object which can position an existing object.
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.
A placeholder is used to show what needs to be filled in at a certain position.
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.
And in XML, it's simply android:hint="someText"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With