Create an EditText widget and add the watcher : EditText « UI « Android






Create an EditText widget and add the watcher

  

package app.test;

import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

public class Test extends Activity implements TextWatcher {

  EditText text;
  int textCount;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    text = new EditText(this);
    text.addTextChangedListener(this);

    setContentView(text);
  }

  /* TextWatcher Implementation Methods */
  public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
  }

  public void onTextChanged(CharSequence s, int start, int before, int end) {
    textCount = text.getText().length();
    setTitle(String.valueOf(textCount));
  }

  public void afterTextChanged(Editable s) {
  }
}

   
    
  








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.Listen EditText event
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