5

I am trying to put a value in EditText but I can not.

The code I edit:

<EditText android:textColor="@color/white" android:id="@id/input_username" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:layout_marginTop="20.0dip" android:hint="@string/input_username_hint" 
    android:ems="10" android:singleLine="true" android:maxLength="140" 
    android:layout_below="@id/input_room_name" android:layout_centerHorizontal="true" />

When I put android:text="user" the genarated apk is not opening.

mustaccio
  • 18,234
  • 16
  • 48
  • 57
Naveen Kumar
  • 51
  • 1
  • 1
  • 5
  • Please explain what "not opening" means. If you mean that you are crashing, use LogCat to examine the Java stack trace associated with your crash: https://stackoverflow.com/questions/23353173/unfortunately-myapp-has-stopped-how-can-i-solve-this – CommonsWare Aug 16 '15 at 14:15

2 Answers2

5

Do this:

editText.setText("Your default text");

But if you want to show that gray text that disappears when the user starts to type, you're looking for android:hint.

On xml:

android:hint="Your default text"

On java:

editText.setHint("Your default text");

On kotlin:

editText.hint = "Your default text"
Mauker
  • 11,237
  • 7
  • 58
  • 76
3

In your .xml file,

specify

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="user" />

or

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:hint="user" />

If you want to do it in program

do this

EditText et = (EditText)findViewById(R.id.your_edittext_id);
et.setText("user");

or

et.setHint("user");
pptang
  • 1,931
  • 1
  • 15
  • 18