Android UI How to - Set text to EditText








The following code shows how to Set text to EditText.

Example

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">
/*w  ww.  j a va 2  s  . c  om*/
    <EditText xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/field"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:singleLine="false"
        />

</LinearLayout>

Java code.

package com.java2s.app;
//  w w w  . jav  a2 s. co  m
import android.app.Activity;
import android.os.Bundle;
import android.widget.EditText;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.activity_main);
        EditText fld=(EditText)findViewById(R.id.field);
        fld.setText("java2s.com");
    }
}
null