Listen EditText event : EditText « UI « Android






Listen EditText event

  

package app.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class Test extends Activity implements OnEditorActionListener {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    EditText text1 = (EditText) findViewById(R.id.text1);
    text1.setOnEditorActionListener(this);
    EditText text2 = (EditText) findViewById(R.id.text2);
    text2.setOnEditorActionListener(this);
  }

  @Override
  public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

    return false;
  }
}
//main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical">
  <EditText
    android:id="@+id/text1"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionSearch"
  />
  <EditText
    android:id="@+id/text2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionGo"
  />
</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.Adding EditText to Activity
6.EditText focus event listener
7.Change color and size for EditText
8.Get value from EditText
9.Note Editor
10.Create Edit Text