当我在EditText上删除文本时出现SearchView错误

时间:2019-01-05 08:50:11

标签: java android searchview

我尝试使用<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA_Compatible" content="ie=edge"> <title> Test</title> <script > /*to put the user input in div tag*/ function myFunction(){ const userInput=document.querySelector("#firstinput"); const output=document.querySelector("#result"); output.innerHTML=userInput.value;//this parte overwrite the first input } </script> </head> <body> <body> <div id="container"> <div id="values"> <input id="firstinput" type="text" placeholder="Enter 2 positive figures"> <button id="submit" onclick="myFunction()">Submit</button> </div> <div id="result"></div> </div> </body> </html>searchview上实现RecyclerView。一切顺利,直到我尝试删除EditText上的所有文本为止。我的应用程序停止工作。

我尝试为Text为null时应用必须执行的操作添加一些条件:

FragmentHome.java

EditText

Adapter.Java

edSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

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

            }

            @Override
            public void afterTextChanged(Editable s) {
                adapter.getFilter().filter(s);

            }
        });

0 个答案:

没有答案