小编Tim*_*Tim的帖子

如何以编程方式关闭SearchView?

我目前SearchView在我的应用程序的操作栏中有一个.当我单击搜索图标时,SearchView扩展和键盘会按预期弹出.单击SearchView框中的"X" SearchView将按预期关闭.但是,当SearchView激活并按下"后退"按钮时,我的应用程序将退出.这是正确的行为,但我现在要做的是捕获后退按钮,只是让它SearchViewSearchView可见时关闭(不是我的应用程序).有没有办法SearchView OnCloseListener()按后退按钮以编程方式调用?例如,像这样:

// On a back button press, if we are currently searching,
// close the SearchView. Otherwise, invoke normal back button
// behavior.
public boolean onKeyDown(int keyCode, KeyEvent event) {
   if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isSearchViewVisible) {
            SearchView searchView = (SearchView) menu.findItem(R.id.searchBox)
               .getActionView();

            // This method does not exist
            searchView.invokeClose();
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}
Run Code Online (Sandbox Code Playgroud)

android searchview

64
推荐指数
6
解决办法
6万
查看次数

Android 4.4中快速滚动的问题

我编写了一个应用程序,其布局中包含一个支持快速滚动的ListView(即拖动滚动条滑块可以让您快速向上或向下滚动列表).这适用于所有版本的Jelly Bean(4.1-4.3).但是,在我更新到Kit Kat后,快速滚动不再有效,我的滚动条只是一个普通的滚动条.但是,如果我退出我的应用程序并重新登录,则会出现快速滚动.如何快速滚动以在Kit Kat中持续工作?我已经复制并粘贴了下面的列表视图适配器代码:

// Adds section popup for fast scroll
class NameListAdapter extends  SimpleAdapter implements SectionIndexer  {
    HashMap<String, Integer> alphaIndexer;
    private String[] sections;
    private ArrayList<String> sectionList;
    private List<HashMap<String, String>> data = null;

    public NameListAdapter (Context context, List<HashMap<String, String>> data, 
            int resource, String[] from, int[] to) {
        super(context, data, resource, from, to);
        alphaIndexer = new HashMap<String, Integer>();
        sectionList = new ArrayList<String>();
        this.data = data;
        int size = data.size();

        for (int i = 0; i < size; i++) {
            HashMap<String, String> …
Run Code Online (Sandbox Code Playgroud)

android android-listview android-4.4-kitkat

18
推荐指数
1
解决办法
5052
查看次数