android QuickSearchBox 流程浅析

启动搜索

SearchActivity.java

protected SearchActivityView setupContentView() {
    setContentView(R.layout.search_activity);
    return (SearchActivityView) findViewById(R.id.search_activity_view);
}

自定义view

SearchActivityView
自定义EditText
QueryTextView
添加监听事件

mQueryTextView.addTextChangedListener(new SearchTextWatcher());
变化后执行

if (mQueryListener != null) {
    mQueryListener.onQueryChanged();
}
回调到activity

mSearchActivityView.setQueryListener(new SearchActivityView.QueryListener() {
    public void onQueryChanged() {
        updateSuggestionsBuffered();
    }
});
private void updateSuggestionsBuffered() {
    if (DBG)
        Log.d(TAG, "updateSuggestionsBuffered()");
    mHandler.removeCallbacks(mUpdateSuggestionsTask);//updateSuggestions();
    long delay = getConfig().getTypingUpdateSuggestionsDelayMillis();
    mHandler.postDelayed(mUpdateSuggestionsTask, delay);
}
public void updateSuggestions() {
    if (DBG)
        Log.d(TAG, "updateSuggestions()");
    final String query = CharMatcher.WHITESPACE.trimLeadingFrom(getQuery());
    getQsbApplication().getSourceTaskExecutor().cancelPendingTasks();
    getCorporaToQuery(new Consumer>() {
        @Override
        public boolean consume(List corporaToQuery) {
            updateSuggestions(query, corporaToQuery);
            return true;
        }
    });
}
通过各个查询,将数据通过adapter显示到自定义listview上

自定义listview

SuggestionsView

基本流程是这样的,后面慢慢分析吧!

你可能感兴趣的:(android源码分析)