SearchView+RecyclerView+GreenDao的搜索功能实现(2)

转载地址:http://blog.csdn.net/oushangfeng123/article/details/48847293


简单的界面效果如下

①打开搜索框显示的是历史和热词,历史可删除②点击某一项,显示搜索的单词和结果

③单词联想

布局如下,通过一个RecyclerView控制显示三种情况的显示

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                tools:context=".MainActivity">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/material_primary"
        android:theme="@style/ToolBarStyle"
        app:popupTheme="@style/Theme.AppCompat.Light">
    </android.support.v7.widget.Toolbar>

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar"
        android:background="@color/material_icons"
        android:scrollbars="none"/>

    <TextView
        android:id="@+id/tv_tip"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textSize="25sp"
        android:textColor="@color/material_red_a700"
        android:text="Open The SearchView"
        android:layout_centerInParent="true"/>

</RelativeLayout>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

①界面初始化,简单设置下Toolbar,RecyclerView , 
mHistoryOrAllSearchList用于存放历史或联想词;mHotSearchList用于存放热词  
SharedPreUtil.readString(Constant.OPENTIME).isEmpty()用来模拟版本变化更新数据库 
更新数据库会将上版本的热词和联想词删除,涉及到大数据量,所以开线程操作mKeywordsTableDao.getSession().runInTx

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Toolbar mToolbar = (Toolbar) findViewById(R.id.toolbar);
        if (mToolbar == null) {
            return;
        }
        mToolbar.setTitle(R.string.app_name);
        setSupportActionBar(mToolbar);

        RecyclerView mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
        StaggeredGridLayoutManager mManager = new StaggeredGridLayoutManager(2, 
                                                StaggeredGridLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(mManager);
        mRecyclerView.addItemDecoration(new SpacesItemDecoration(5));

        mAdapter = new SearchAdapter(this);
        mAdapter.setItemClickLitener(this);

        mRecyclerView.setAdapter(mAdapter);

        mHistoryOrAssociativeSearchList = new ArrayList<>();
        mHotSearchList = new ArrayList<>();

        mKeywordsTableDao = getSearchKeywordsTableDao(mKeywordsTableDao);

        if (SharedPreUtil.readString(Constant.OPENTIME).isEmpty()) {
            // 词库版本有更新才去更新数据库的热词和练习词
            final List<SearchKeywords> keywordses = new ArrayList<>();

            // 热词
            keywordses.add(new SearchKeywords("women", 12, -1, Constant.SEARCH_KEYWORDS_HOT));
            keywordses.add(new SearchKeywords("men", 10, -1, Constant.SEARCH_KEYWORDS_HOT));
            keywordses.add(new SearchKeywords("beauty", 16, -1, Constant.SEARCH_KEYWORDS_HOT));
            keywordses.add(new SearchKeywords("makeup", 2, -1, Constant.SEARCH_KEYWORDS_HOT));
            keywordses.add(new SearchKeywords("clothes", 6, -1, Constant.SEARCH_KEYWORDS_HOT));

            // 联想词
            keywordses.add(new SearchKeywords("women", 12, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("men", 10, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("beauty", 16, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("makeup", 2, -1,   
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("clothes", 6, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("cute", 26, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("watch", 32, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));
            keywordses.add(new SearchKeywords("sexy", 16, -1, 
                            Constant.SEARCH_KEYWORDS_ASSOCIATIVE));

            mKeywordsTableDao.getSession().runInTx(new Runnable() {
                @Override
                public void run() {
                    // 避免数据太多阻塞主线程
                    // 清除旧版本的热词和联想词
                    clearTopAndAssociativeSearchKeyWords();
                    insertSearchKeywordsToDb(keywordses);
                }
            });

            SharedPreUtil.writeString(Constant.OPENTIME, System.currentTimeMillis() + "");
        }

    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71

②RecyclerView适配器的设计

会有三种视图模式,暴露方法获取当前模式和设置当前模式

    // 历史和热词模式
    public static final int MODE_KEYWORDS_REVIEW = 0;
    // 搜索结果模式
    public static final int MODE_RESULT = 1;
    // 联想匹配模式
    public static final int MODE_KEYWORDS_MATCH = 2;

    public int getCurrentMode() {
        return mCurrentMode;
    }

    public void setCurrentMode(int currentMode) {
        this.mCurrentMode = currentMode;
    }

    private int mCurrentMode;
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16

填充数据有两个成员变量

    /**
     * 搜索热词
     */
    private List<String> mHotSearchList;

    public List<String> getHotSearchList() {
        return mHotSearchList;
    }

    public void setHotSearchList(List<String> allSearchList) {
        this.mHotSearchList = allSearchList;
    }

    /**
     * 搜索历史,或者是匹配的单词
     */
    private List<String> mHistoryOrAssociativeSearchList;

    public List<String> getHistoryOrAssociativeSearchList() {
        return mHistoryOrAssociativeSearchList;
    }

    public void setHistoryOrAssociativeSearchList(List<String> historyOrAssociativeSearchList) {
        this.mHistoryOrAssociativeSearchList = historyOrAssociativeSearchList;
    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25

有四种View类型: 
①VIEW_TYPE_TIP ,标题,在显示历史和热搜的时候为标识类型;显示搜索结果的时候标识搜索结果的搜索单词 
②VIEW_TYPE_KEYWORD ,搜索单词 
③VIEW_TYPE_RESULT ,搜索结果 
④VIEW_TYPE_DELETE_HISTORY,一键清空的布局 

    private final int VIEW_TYPE_TIP = 0;
    private final int VIEW_TYPE_KEYWORD = 1;
    private final int VIEW_TYPE_RESULT = 2;
    private final int VIEW_TYPE_DELETE_HISTORY = 3;

    @Override
    public SearchAdapter.RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        RecyclerViewHolder viewHolder;
        switch (viewType) {
            case VIEW_TYPE_TIP:
                viewHolder = new RecyclerViewHolder
                (LayoutInflater.from(mContext).inflate(R.layout.item_search_head, parent, false));
                return viewHolder;
            case VIEW_TYPE_KEYWORD:
                View view LayoutInflater.from(mContext).inflate(R.layout.item_search, 
                parent, false);
                viewHolder = new RecyclerViewHolder(view);
                view.findViewById(R.id.iv_delete).setOnClickListener(this);
                view.findViewById(R.id.ll_search).setOnClickListener(this);
                return viewHolder;
            case VIEW_TYPE_RESULT:
                viewHolder = new RecyclerViewHolder
               (LayoutInflater.from(mContext).inflate(R.layout.item_search_result, parent, false));
                return viewHolder;
            case VIEW_TYPE_DELETE_HISTORY:
                View view1 = 
                LayoutInflater.from(mContext).inflate(R.layout.item_search_delete_history, parent, 
                false);
                viewHolder = new RecyclerViewHolder(view1);
                view1.findViewById(R.id.tv_clear_history).setOnClickListener(this);
                return viewHolder;
        }
        return null;
    }

    @Override
    public void onBindViewHolder(SearchAdapter.RecyclerViewHolder holder, int position) {
        switch (getItemViewType(position)) {
            case VIEW_TYPE_TIP:
                StaggeredGridLayoutManager.LayoutParams lp = 
                (StaggeredGridLayoutManager.LayoutParams) holder.mHeadLayout.getLayoutParams();
                lp.setFullSpan(true);
                if (mCurrentMode != MODE_RESULT) {
                // 历史和热词模式,位置不为0,说明同时存在历史和热搜,标配自然是“Hot”,如果等于0,
                    holder.mTitleText.setText(position != 0 ? "Hot" : mHistoryExist ? 
                    "History" : "Hot");
                } else {
                // 结果模式,搜索单词
                    holder.mTitleText.setText("word: " + mSearchWord);
                }
                break;

            case VIEW_TYPE_DELETE_HISTORY:
                // 不用做任何事,只是一个点击事件清空历史
                StaggeredGridLayoutManager.LayoutParams lp3 = 
                (StaggeredGridLayoutManager.LayoutParams) ((ViewGroup) 
                holder.mClearHistoryText.getParent()).getLayoutParams();
                lp3.setFullSpan(true);
                break;

            case VIEW_TYPE_KEYWORD:

                StaggeredGridLayoutManager.LayoutParams lp1 = 
                (StaggeredGridLayoutManager.LayoutParams) ((ViewGroup) 
                holder.mSearchKeyWordText.getParent()).getLayoutParams();
                lp1.setFullSpan(true);

                if (mCurrentMode == MODE_KEYWORDS_MATCH) {
                // 联想匹配模式
                    if (mHistoryExist) {
                        holder.mDeleteImg.setVisibility(View.GONE);
        holder.mSearchKeyWordText.setText(mHistoryOrAssociativeSearchList.get(position));
                        holder.mSearchLayout.setTag(position);
                    }
                } else if (mCurrentMode == MODE_KEYWORDS_REVIEW) {
                // 历史和热搜模式
                    if (mHistoryExist) {
                    // 存在历史数据
                        if (position < mHistoryOrAssociativeSearchList.size() + 1) { 
                        // 删除按钮设置为可见,历史可以删除                    
                        holder.mSearchKeyWordText
                        .setText(mHistoryOrAssociativeSearchList.get(position - 1));
                            holder.mDeleteImg.setVisibility(View.VISIBLE);
                            holder.mDeleteImg.setTag(position - 1);
                            holder.mSearchLayout.setTag(position - 1);
                        } else {
                        // 设置热搜数据
//                            DebugLog.e("position=" + position);
                            holder.mDeleteImg.setVisibility(View.GONE);
                            holder.mSearchKeyWordText.setText(mHotSearchList.get(position - 3 - 
                            mHistoryOrAssociativeSearchList.size()));
                            holder.mSearchLayout.setTag(position - 3);
                        }
                    } else if (mHotExist) {
                    // 只存在热搜数据
                        holder.mDeleteImg.setVisibility(View.GONE);
                        holder.mSearchKeyWordText.setText(mHotSearchList.get(position - 1));
                        holder.mSearchLayout.setTag(position - 1);
                    }
                }
                break;
            case VIEW_TYPE_RESULT:
            // 搜索结果
                StaggeredGridLayoutManager.LayoutParams lp2 = 
                (StaggeredGridLayoutManager.LayoutParams) ((ViewGroup) 
                holder.mResultText.getParent()).getLayoutParams();
                lp2.setFullSpan(true);
                holder.mResultText.setText("The search word is " + mSearchWord);
                break;

        }
    }

    @Override
    public int getItemViewType(int position) {
        if (mCurrentMode == MODE_KEYWORDS_REVIEW) {
            int hotTitlePosition = 0;
            if (mHistoryExist && mHotExist) {
                // 同时存在的时候才有第二个标题
                hotTitlePosition = mHistoryOrAssociativeSearchList.size() + 1 + 1;
            }
            if (mHistoryExist && position == mHistoryOrAssociativeSearchList.size() + 1) {
                // 有历史记录存在,历史纪录后面是一个一键情空历史按钮
                return VIEW_TYPE_DELETE_HISTORY;
            }
            return position == 0 || position == hotTitlePosition ? VIEW_TYPE_TIP : 
            VIEW_TYPE_KEYWORD;
        } else if (mCurrentMode == MODE_KEYWORDS_MATCH) {
            return VIEW_TYPE_KEYWORD;
        } else if (mCurrentMode == MODE_RESULT) {
            return position == 0 ? VIEW_TYPE_TIP : VIEW_TYPE_RESULT;
        }
        return -1;
    }

    boolean mHistoryExist;
    boolean mHotExist;

    @Override
    public int getItemCount() {
        int itemCount = 0;
        if (mCurrentMode == MODE_KEYWORDS_REVIEW) {
            mHistoryExist = mHistoryOrAssociativeSearchList != null && 
            mHistoryOrAssociativeSearchList.size() > 0;
            mHotExist = mHotSearchList != null && mHotSearchList.size() > 0;
            if (mHistoryExist) {
                // 存在历史,加个历史的标题
                itemCount += mHistoryOrAssociativeSearchList.size() + 1;
                // 加个一键清空历史的按钮
                itemCount += 1;
                if (mHotExist) {
                    // 存在热搜,加个热搜的标题
                    itemCount += mHotSearchList.size() + 1;
                }
            } else {
                // 不存在历史
                if (mHotExist) {
                    // 存在热搜,加个热搜的标题
                    itemCount += mHotSearchList.size() + 1;
                }
            }
        } else if (mCurrentMode == MODE_KEYWORDS_MATCH) {
            mHistoryExist = mHistoryOrAssociativeSearchList != null && 
            mHistoryOrAssociativeSearchList.size() > 0;
            if (mHistoryExist) {
                itemCount += mHistoryOrAssociativeSearchList.size();
            }
        } else if (mCurrentMode == MODE_RESULT) {
            // 结果是标题加text显示搜索词语
            return itemCount += 2;
        }

        return itemCount;
    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174

菜单的设置

    private MenuItem mSearchItem;

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main, menu);

        mSearchItem = menu.findItem(R.id.action_search);

        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchItem);

        final SearchView.SearchAutoComplete searchEditText = (SearchView.SearchAutoComplete) 
        searchView.findViewById(R.id.search_src_text);

        searchView.setQueryHint("Search");

        // 将搜索按钮放到搜索输入框的外边
        searchView.setIconifiedByDefault(false);

        // 设置输入框底部的横线的颜色
        View searchPlate = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
        searchPlate.setBackgroundResource(R.mipmap.ic_searchview_plate);
      searchPlate.getBackground().setColorFilter(getResources().getColor(R.color.material_a
      ccent), PorterDuff.Mode.SRC_ATOP);

        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                // 提交查询条件
                DebugLog.e("提交查询:" + query);
                submitKeywords(query);
                searchEditText.setText("");
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // 这里做搜索联想
                if (mAdapter.getCurrentMode() == SearchAdapter.MODE_RESULT) {
                    DebugLog.e("搜索结果模式,不做处理");
                    return true;
                }
                if (newText.isEmpty()) {
                    DebugLog.e("搜索为空,显示历史和热词");
                    showHistoryAndHotKeywords();
                } else {
                    DebugLog.e("搜索词不为空,显示匹配");
                    mHotSearchList.clear();
                    mHistoryOrAssociativeSearchList.clear();
                    insertMatchKeywordsToRecycleView(mHistoryOrAssociativeSearchList, newText);
                    mAdapter.setCurrentMode(SearchAdapter.MODE_KEYWORDS_MATCH);
                    mAdapter.setHistoryOrAssociativeSearchList(mHistoryOrAssociativeSearchList);
                    mAdapter.notifyDataSetChanged();
                }

                return true;
            }
        });

        return true;
    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

点击事件的处理

    /**
     * 提交结果
     *
     * @param query
     */
    private void submitKeywords(String query) {
        mAdapter.setCurrentMode(SearchAdapter.MODE_RESULT);
        final SearchKeywords keywords = new SearchKeywords(query, -1, System.currentTimeMillis(), 
        Constant.SEARCH_KEYWORDS_HISTORY);
        insertHistorySearchKeywordsToDb(keywords);
        hideKeybord(MainActivity.this, MainActivity.this.getCurrentFocus());
        mAdapter.setSearchWord(query);
        mAdapter.notifyDataSetChanged();
        MenuItemCompat.collapseActionView(mSearchItem);
    }

    /**
     * 显示历史和热词
     */
    private void showHistoryAndHotKeywords() {
        mAdapter.setCurrentMode(SearchAdapter.MODE_KEYWORDS_REVIEW);
        mHotSearchList.clear();
        mHistoryOrAssociativeSearchList.clear();
        insertKeywordsToRecyclerView(mHistoryOrAssociativeSearchList, 
        Constant.SEARCH_KEYWORDS_HISTORY);
        insertKeywordsToRecyclerView(mHotSearchList, Constant.SEARCH_KEYWORDS_HOT);
        mAdapter.setHistoryOrAssociativeSearchList(mHistoryOrAssociativeSearchList);
        mAdapter.setHotSearchList(mHotSearchList);
        mAdapter.notifyDataSetChanged();
    }

    @Override
    public void onItemClick(View view, int position) {
        switch (view.getId()) {
            case R.id.iv_delete:
                hideKeybord(MainActivity.this, MainActivity.this.getCurrentFocus());
                DebugLog.e("删除历史: " + mHistoryOrAssociativeSearchList.get(position));
                clearSearchKeyWords(mHistoryOrAssociativeSearchList.get(position));
                mHistoryOrAssociativeSearchList.remove(position);
                mAdapter.notifyDataSetChanged();
                break;
            case R.id.ll_search:
                boolean historyExist = mHistoryOrAssociativeSearchList != null && 
                mHistoryOrAssociativeSearchList.size() > 0;
                boolean hotExist = mHotSearchList != null && mHotSearchList.size() > 0;
                String keyword = null;
                if (historyExist) {
                    if (position >= mHistoryOrAssociativeSearchList.size()) {
                        // 点击的是热搜
                        keyword = mHotSearchList.get(position - 
                        mHistoryOrAssociativeSearchList.size());
                        DebugLog.e("点击的是热搜: " + keyword);
                    } else {
                        keyword = mHistoryOrAssociativeSearchList.get(position);
                        if (mAdapter.getCurrentMode() == SearchAdapter.MODE_KEYWORDS_MATCH) {
                            DebugLog.e("点击的是联想的匹配: " + keyword);
                        } else if (mAdapter.getCurrentMode() == SearchAdapter.MODE_KEYWORDS_REVIEW) {
                            DebugLog.e("点击的是历史: " + keyword);
                        }
                    }
                } else if (hotExist) {
                    keyword = mHotSearchList.get(position);
                    DebugLog.e("点击的是热搜: " + keyword);
                }
                if (keyword != null) {
                    submitKeywords(keyword);
                    MenuItemCompat.collapseActionView(mSearchItem);
                }
                break;
            case R.id.tv_clear_history:
                DebugLog.e("点击了一键清空历史");
                clearHisotySearchKeyWords();
                mHistoryOrAssociativeSearchList.clear();
                mAdapter.setCurrentMode(SearchAdapter.MODE_KEYWORDS_REVIEW);
                mAdapter.notifyDataSetChanged();
                break;
        }
    }
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78

总结:

可能说得不是很清楚,附上demo,跑一下,看下源码估计就差不多了>_<

SearchView+GreenDao搜索功能实现


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值