首页 > 解决方案 > 使用 EditText.setText(value) 时停止刷新我的键盘

问题描述

下面是我与 rxandroid 的编辑文本。问题是当我在搜索框中删除某些字符'\\'和setText时我的键盘刷新。所以它让我的键盘切换回字母(图 1),而我想保留数字和特殊字符(图 2)。有没有办法在不刷新页面的情况下设置 EditText 文本?

 SearchEditText = RxTextView.textChanges(searchbox)
                .map(CharSequence::toString)
                .debounce(2, TimeUnit.SECONDS)
                .distinctUntilChanged()
                //.observeOn(Schedulers.computation()) // can test without this
                //.switchMap(RegrexAndActualNumberHelper::TrySearchValidation) // can test without this
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(result -> {
                //    searchbox.setText(result); // settext make the page refresh and reset the keyboard to alphabets
                    searchbox.setSelection(searchbox.getText().length()); // move the cursor b to end of the line.
                    if( !result.isEmpty() ){
                        getInventoryItems(view, searchbox, recycler);
                    }
                });

在此处输入图像描述

在此处输入图像描述

标签: javaandroidandroid-edittext

解决方案


推荐阅读