Get value from EditText : EditText « UI « Android






Get value from EditText

  


package app.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class Test extends Activity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTitle("EditTextActivity");
    setContentView(R.layout.main);
    find_and_modify_text_view();
  }

  private void find_and_modify_text_view() {
    Button get_edit_view_button = (Button) findViewById(R.id.get_edit_view_button);
    get_edit_view_button.setOnClickListener(get_edit_view_button_listener);
  }

  private Button.OnClickListener get_edit_view_button_listener = new Button.OnClickListener() {
    public void onClick(View v) {
      EditText edit_text = (EditText) findViewById(R.id.edit_text);
      CharSequence edit_text_value = edit_text.getText();
      setTitle("EditText:" + edit_text_value);
    }
  };

}

//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical" android:layout_width="fill_parent"
  android:layout_height="fill_parent">

  <EditText android:id="@+id/edit_text" android:layout_width="fill_parent"
    android:layout_height="wrap_content" android:text="Input text here" />

  <Button android:id="@+id/get_edit_view_button"
    android:layout_width="wrap_content" android:layout_height="wrap_content"
    android:text="Get value from EditView" />

</LinearLayout>

   
    
  








Related examples in the same category

1.Use EditText to accept user input
2.Parse Uri from EditText control
3.Get text from EditText
4.Create an EditText widget and add the watcher
5.Listen EditText event
6.Adding EditText to Activity
7.EditText focus event listener
8.Change color and size for EditText
9.Note Editor
10.Create Edit Text