android - EditText.setSelection(end) 没有效果?

标签 android android-layout

我使用下面的代码在 customEditText(EditText) 的 end 设置了 cursor 但它没有带来任何效果。

customEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                 if (hasFocus) {
                    String customEditTextText = customEditText.getText().toString();
                    int selection = customEditTextText.length();
                    customEditText.setSelection(selection);
                }
            }
});

有人对此有什么想法吗?

最佳答案

我对 AlertDialog 中的 EditText 也有同样的问题。我的解决方案是这样的:

    mEditText.post(new Runnable() {
        @Override
        public void run() {
            mEditText.setSelection(mEditText.length());
        }
    });

关于android - EditText.setSelection(end) 没有效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23719492/

相关文章:

android - 如何在滚动 ListView 上显示类似 Whatsapp 的日期

android - 在除 android L 之外的所有 android 版本上获取 TypeNotPresentException 后跟 ClassNotFoundException 或 NoClassDefFoundError

android - 如何在 fragment 中加载 webview 中的 url 链接?

android - 如何在 Eclipse 中复制或保存 Lint 警告

android - 设置 Uri 时出现位图错误

android - 如何在相对布局内的图像上放置背景?

java - 带有自定义布局的自定义 Android 首选项没有焦点或单击事件

Android相对布局重力填充问题

android - 左边距不适用于 java

android - 底部导航 View : Change the default highlighted Tab when the app launches