Android:Edittext::get Entered Character from the keyboard at any position

标签 android android-edittext

我需要找出插入到 EditText 中的新字符是什么。实际上,我使用 TextChange Listener 来查找文本字段中新输入的字符。例如,如果我一个一个地输入“成功”这个词。我需要获得新输入的角色。如果我在 e 旁边插入 X,我需要检测那个 X 字符。

请提供最好的解决方案

最佳答案

我认为您必须在 edittext 上尝试使用 TextChangedListener 来控制文本输入

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    txtEdit = (EditText) findViewById(R.id.editText1);
    viewText = (TextView) findViewById(R.id.text);

     txtEdit.addTextChangedListener (new TextWatcher() {

          public void beforeTextChanged(CharSequence s, int start, int count, int after) {
              Log.i("TC", "beforeTC " + s.toString() + " "
                      + s.subSequence(start, start + count).toString());
          }

          public void onTextChanged(CharSequence s, int start, int before, int count) {
              Log.i("TC", "onTC " + s.toString() + " "
                      + s.subSequence(start, start + count).toString());
          }

          public void afterTextChanged(Editable s) {
              Log.i("TC", "afterTC " + s.toString());
          }
     });
}

关于Android:Edittext::get Entered Character from the keyboard at any position,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28407704/

相关文章:

java - 在android中排序对象列表

java - 带有 textMultiLine 的 EditText 不起作用

android - 当 EditText 中的数字为 ="integer"时提示不显示

android - TextView 缓冲区类型

android - 将输入的值保存到 RecyclerView 的 EditTexts 中

android - 为什么我的返回堆栈条目计数始终为零?

java.lang.RuntimeException : Unable to resume activity Attempted to access a cursor after it has been closed

java - Firebase 身份验证 : getCurrentUser from different Activities?

Android 无法禁用剪切复制粘贴

java - 如何使用按钮将字符串值从一个 Activity 传递到两个不同的 Activity ?