Android的搜索查看的onclick [英] Android SearchView onclick

查看:168
本文介绍了Android的搜索查看的onclick的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有搜索查看它看起来像这样:

I have searchView which looks like this:

private void setupSearchView() {
    mSearchView = (SearchView) getActivity().findViewById(
            R.id.search_view_neue);
    setSearchViewBackground();
    mSearchView.setOnClickListener(this);
    mSearchView.setOnQueryTextListener(this);
}




    public boolean onQueryTextSubmit(String query) {
    searchcounter = searchcounter + 1;

    setSearchViewBackground();
    ArrayList<WissensdokumenteRecord> documents = settingListContent(new ArrayList<WissensdokumenteRecord>());

    setListAdapter(new NeueWissensdokumentItemAdapter(
            inflater.getContext(), R.layout.row_example, documents));
    InputMethodManager im = (InputMethodManager) getActivity()
            .getSystemService(Context.INPUT_METHOD_SERVICE);
    im.hideSoftInputFromWindow(getActivity().getCurrentFocus()
            .getWindowToken(), 0);

    return false;
}




<SearchView
    android:id="@+id/search_view_neue"
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:background="@drawable/border_searchview"
    android:maxWidth="540dp"
    android:queryHint="Neue Dokumente suchen" >
</SearchView>

因此​​,搜索视图的行为,该键盘通过点击搜索button.Now我可以搜索的东西打开。是否有可能做到通过单击搜索查看的任何地方搜索?有没有人有我一个例子吗?

So, the behaviour of the search view is, that the keyboard opens by clicking the search button.Now I can search for something. Is it possible to do a search by clicking in the searchview anywhere? Does anyone has an example for me?

最良好的祝愿

Best wishes Christine

推荐答案

我能够做到这一点的方式如下:

I managed to do this in the following way:

设置上点击监听器的搜索视图

Setup the search view on click listener

mSearchView.setOnClickListener(this);

抓住onClick事件:

Catch the onClick event:

@Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.searchView:
            mSearchView.onActionViewExpanded();
            break;
    }
}

在这种方式,如果你点击antwhere搜索栏上,键盘和搜索被激活

In this way the keyboard and search are activated if you click antwhere on the search bar.

这篇关于Android的搜索查看的onclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆