【问题标题】:How do I select all the text in an editText after the user is finished typing in it?用户完成输入后,如何选择 editText 中的所有文本?
【发布时间】:2021-01-28 07:26:38
【问题描述】:

我有一个 EditText,里面有一些虚拟文本。当用户完成输入时,我希望能够选择所有文本。

我怎样才能做到这一点?

【问题讨论】:

    标签: android android-studio user-interface android-edittext user-experience


    【解决方案1】:

    你可以使用 Rx 的 debounce 来做到这一点,

        RxTextView.textChanges(editText)
            .debounce(3, TimeUnit.SECONDS)
            .subscribe { textChanged: CharSequence? ->
                Log.d(
                    "TAG",
                    "Stopped typing!"
                )
                editText.selectAll()
            }
    

    【讨论】:

    • editText.selectAll() :这对我来说真正有用。非常感谢。
    【解决方案2】:

    为您的编辑文本创建参考:

    EditText editText = (EditText) findViewById(/* edittext id */);
    

    在其上附加一个文本更改的侦听器:

    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(Editable s) { 
            //get your final string here 
            String str = s.toString();
        }
    
        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {}
    
        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {}
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 1970-01-01
      • 2012-05-12
      相关资源
      最近更新 更多