Best Practices for Handling Search

前端 未结 3 798
旧时难觅i
旧时难觅i 2021-02-13 07:10

I\'ve got a SearchView setup, and I have a loosely decoupled architecture using Retrofit and Otto.

I am wondering what the

3条回答
  •  不知归路
    2021-02-13 07:34

    I think there is no sense to make an API call before user stopped typing. So, you can put a delay, say, 500ms. When user stops typing, after 500ms you make an API call and show the results.

    You can use a Handler's postDelayed method for scheduling search API calls. You can use Handler to control the message queue. You post a delayed Runnable each time user types a character and cancel previous messages. It will look this way:

    public void onTextChanged(CharSequence s, int start, int before, int count) {
        handler.removeCallbacks(searchRunnable);
        handler.postDelayed(searchRunnable, 500);
    }
    

提交回复
热议问题