android - EditText 事件处理程序以获取已按下键的通知

标签 android android-edittext

应用程序需要知道在使用、填充 EditText 期间何时按下新键。它有任何事件处理程序吗?在 iOS 中,UITextField 使用了 shouldChangeCharactersInRange 委托(delegate)方法。

<EditText
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:id="@+id/editText"
        android:layout_alignParentBottom="false"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="18dp"
        android:layout_marginLeft="8dp"
        android:width="100dp"
        android:on/> <----- some event handler need here but only onclick I see

enter image description here

最佳答案

您可以使用 TextChangedListener 为您的 EditText 在编辑文本字段的文本时接收事件

yourEditText.addTextChangedListener(new TextWatcher() {

    public void afterTextChanged(Editable s) {

    }

    public void beforeTextChanged(CharSequence s, int start, int count, int after)  {

    }

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        Log.i("TAG","text = "+yourEditText.getText().toString());
    }
});

关于android - EditText 事件处理程序以获取已按下键的通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37807496/

相关文章:

java - 从 Android 中的 Listview Adapter 访问 Activity 中的 TextView

android - 点击后退按钮时将数据保存在编辑文本中

android - 检查 ListView 内的 EditText 对象中的条目

android - 如何在editText框的右下角显示editText字符限制??下面的例子

android - android 对话框中的 clearFocus 不起作用

android - Xamarin WebView 上的摄像头

Android 媒体编解码器配置失败

java - 我想从 firebase 数据库中的单个 Textview 中获取完整数据

java - 如何从应用程序启用/禁用 WiFi?

Android - 单个 TableRow 中的多个 EditText