Java 类android.support.v4.widget.SearchViewCompat.OnCloseListenerCompat 实例源码

项目:informant-droid    文件:LoaderCustomSupport.java   
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Since this
                // is a simple array adapter, we can just have it do the filtering.
                mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
                mAdapter.getFilter().filter(mCurFilter);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null, true);
                        }
                        return true;
                    }

        });
        MenuItemCompat.setActionView(item, searchView);
    }
}
项目:V.FlyoutTest    文件:LoaderCustomSupport.java   
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Since this
                // is a simple array adapter, we can just have it do the filtering.
                mCurFilter = !TextUtils.isEmpty(newText) ? newText : null;
                mAdapter.getFilter().filter(mCurFilter);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null, true);
                        }
                        return true;
                    }

        });
        MenuItemCompat.setActionView(item, searchView);
    }
}
项目:Extrace_UserApp    文件:TransNodeListActivity.java   
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // 客户列表菜单
    inflater.inflate(R.menu.transnode_list, menu);

    // 获取“搜索按钮”菜单控件
    MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) item.getActionView();
    if (searchView != null) {

        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
                    @Override
                    public boolean onQueryTextChange(String newText) {

                        return true;
                    }

                    // 当搜索结果提交时执行
                    @Override
                    public boolean onQueryTextSubmit(String query) {
                        if (!TextUtils.isEmpty(query)) {
                            RefreshList(query);
                            SearchViewCompat.setQuery(searchView, null,
                                    true);
                        }
                        return true;
                    }
                });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat
                                .getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null,
                                    true);
                        }
                        return true;
                    }

                });
        MenuItemCompat.setActionView(item, searchView);
    }
}
项目:Extrace_UserApp    文件:CustomerListActivity.java   
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // 客户列表菜单
    inflater.inflate(R.menu.customer_list, menu);

    // 获取“搜索按钮”菜单控件
    MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) item.getActionView();
    if (searchView != null) {

        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
                    @Override
                    public boolean onQueryTextChange(String newText) {

                        return true;
                    }

                    // 当搜索结果提交时执行
                    @Override
                    public boolean onQueryTextSubmit(String query) {
                        if (!TextUtils.isEmpty(query)) {
                            RefreshList(query);
                            SearchViewCompat.setQuery(searchView, null,
                                    true);
                        }
                        return true;
                    }
                });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat
                                .getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null,
                                    true);
                        }
                        return true;
                    }

                });
        MenuItemCompat.setActionView(item, searchView);
    }
}
项目:Extrace_UserApp    文件:TransNodeTabFragment.java   
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // TODO Auto-generated method stub
    MenuItem search = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) search.getActionView();
    searchView.setQueryHint("网点名称,区域码...");
    if (searchView != null) {

        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
                    @Override
                    public boolean onQueryTextChange(String newText) {

                        return true;
                    }

                    // 当搜索结果提交时执行
                    @Override
                    public boolean onQueryTextSubmit(String query) {
                        if (!TextUtils.isEmpty(query)) {
                            loadNodesLatlng(query);
                            SearchViewCompat.setQuery(searchView, null,
                                    true);
                        }
                        return true;
                    }
                });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat
                                .getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null,
                                    true);
                        }
                        return true;
                    }

                });
        MenuItemCompat.setActionView(search, searchView);
    }
    super.onCreateOptionsMenu(menu, inflater);
}
项目:informant-droid    文件:LoaderCursorSupport.java   
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Update
                // the search filter, and restart the loader to do a new query
                // with this filter.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                // Don't do anything if the filter hasn't actually changed.
                // Prevents restarting the loader when restoring state.
                if (mCurFilter == null && newFilter == null) {
                    return true;
                }
                if (mCurFilter != null && mCurFilter.equals(newFilter)) {
                    return true;
                }
                mCurFilter = newFilter;
                getLoaderManager().restartLoader(0, null, CursorLoaderListFragment.this);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null, true);
                        }
                        return true;
                    }

        });
        MenuItemCompat.setActionView(item, searchView);
    }
}
项目:V.FlyoutTest    文件:LoaderCursorSupport.java   
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS
            | MenuItemCompat.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView,
                new OnQueryTextListenerCompat() {
            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Update
                // the search filter, and restart the loader to do a new query
                // with this filter.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                // Don't do anything if the filter hasn't actually changed.
                // Prevents restarting the loader when restoring state.
                if (mCurFilter == null && newFilter == null) {
                    return true;
                }
                if (mCurFilter != null && mCurFilter.equals(newFilter)) {
                    return true;
                }
                mCurFilter = newFilter;
                getLoaderManager().restartLoader(0, null, CursorLoaderListFragment.this);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView,
                new OnCloseListenerCompat() {
                    @Override
                    public boolean onClose() {
                        if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                            SearchViewCompat.setQuery(searchView, null, true);
                        }
                        return true;
                    }

        });
        MenuItemCompat.setActionView(item, searchView);
    }
}