android - TextView 中的 OnWrite

标签 android keyboard

我有一个 TextView,我想控制用户何时插入字母。

Ex.

s -> search s in database and show results
st -> search st in database and show results
sta -> search sta in database and show results
stac -> search stac in database and show results
stack -> search stack in database and show results
...
...
...

我该怎么做?

最佳答案

用户 TextWatcher当用户在 EditText 中输入任何文本时获取文本

searchText.addTextChangedListener(new TextWatcher() {

                public void afterTextChanged(Editable s) {

                        String text = searchText.getText().toString();
                        if (text != null && text.length() > 0) {
                                                // Call your method that will get Data from Database and then update then data to the ListView or anything you want
                            getSearchDataFromDBagianUserText(text); 
                        }

                }

                public void beforeTextChanged(CharSequence s, int start, int count,
                        int after) {
                }

                public void onTextChanged(CharSequence s, int start, int before, int count) {

                }
            });

关于android - TextView 中的 OnWrite,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9101764/

相关文章:

java - retrofit转换为json字符串时出现Conversion Exception如何解决

android - Listview 在其 View 之间有透明空间 - 如何删除它?

android - ImageView setVisibility(0) 和空指针异常

linux - 启动时禁用键盘 FnLock

android - React Native Keyboard 推送标题(Android)

java.lang.IllegalStateException : Another SimpleCache instance uses the folder: 错误

android - 如何使用Mvc JsonResult返回纯html

C# SerialPort - 模拟 pos 键盘

Android 键盘字符验证

android - 在 iOS 的 ReactJS 中显示十进制键盘