【问题标题】:Android - Insert text at cursor position in EditText using custom keyboardAndroid - 使用自定义键盘在 EditText 中的光标位置插入文本
【发布时间】:2017-07-05 11:59:08
【问题描述】:

我有一个固定在屏幕上的自定义键盘,用于编辑 EditText

 myKeyboard.setListener(new CustomKeyboard.KeyboardListener() {
        @Override
        public void onChanged(char key, String value)
        {
            myEditText.setText(value);
        }

我已经使用this solution 禁用了默认键盘,效果很好。

唯一的问题是,当我在EditText 内移动光标时,我输入的任何内容都会添加到字符串的末尾,而不考虑光标位置,它会在EditText 的开头再次移动。 我该如何解决这个问题?

【问题讨论】:

    标签: android android-edittext android-cursor


    【解决方案1】:

    试试EditText的getSelectionEnd()方法

    myEditText.getSelectionEnd(); 
    

    【讨论】:

      猜你喜欢
      • 2014-06-08
      • 2012-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多