Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display a message inside Android Edit Text Field

Hai, I have an Android Program with one text field. I need to display a message inside that textfield when it loads on an emulator. When the user clicks inside that textbox that message should dispappear. For Ex: Please enter name Can any one post some sample code over here...

like image 321
Sanjeev Avatar asked Jul 23 '10 12:07

Sanjeev


People also ask

How do you edit a text box on android?

Step 1: Create a new project in Android Studio and name it EditTextExample. Step 2: Now Open res -> layout -> xml (or) activity_main. xml and add following code. In this code we have added multiple edittext and a button with onclick functionality.

What is the difference between edit text and text TextView android?

EditText is used for user input. TextView is used to display text and is not editable by the user. TextView can be updated programatically at any time.

How do you add edit text to the android application?

How to include a Edittext in an Android App: First of all, create a new Android app, or take an existing app to edit it. In both the case, there must be an XML layout activity file and a Java class file linked to this activity. Open the Activity file and include a Edittext field in the layout (activity_main.


1 Answers

Just use or call setHint on the object. Hint text to display when the text is empty.

<EditText
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="18px"
        android:gravity="left"
        android:hint="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse egestas ullamcorper facilisis." />
like image 172
Pentium10 Avatar answered Oct 25 '22 08:10

Pentium10