IndyS
IndyS

Reputation: 59

Prompt for EditText

I'm trying to get a prompt for my EditText to show such as "Please Enter Answer Here" and when the user taps on the EditText to type thier Answer the text should disappear and be blank for them to enter their answer in.

As of right now this is what I have for my .xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".AnswerActivity" >

<EditText
    android:id="@+id/edittxt_answer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textMultiLine" />
</RelativeLayout>

In my .java

public class AnswerActivity extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_answer);

    EditText ans = (EditText) findViewById(R.id.edittxt_answer);
    //Continue with acitivty.... 
}

Upvotes: 1

Views: 119

Answers (3)

panini
panini

Reputation: 2026

use

android:hint="@string/answer_hint"

in your XML

Upvotes: 0

codeMagic
codeMagic

Reputation: 44571

It's called hint you can set it in your xml with android:hint or in java with setHint()

<EditText
android:id="@+id/edittxt_answer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:hint="Please enter your answer here" />

Upvotes: 1

Szymon
Szymon

Reputation: 43023

You can just use android:hint attribute and you won't need any code for that.

<EditText
    android:id="@+id/edittxt_answer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textMultiLine"
    android:hint="Please Enter Answer Here" />

Upvotes: 2

Related Questions