Example usage for android.widget SearchView setVisibility

List of usage examples for android.widget SearchView setVisibility

Introduction

In this page you can find the example usage for android.widget SearchView setVisibility.

Prototype

@RemotableViewMethod
public void setVisibility(@Visibility int visibility) 

Source Link

Document

Set the visibility state of this view.

Usage

From source file:de.enlightened.peris.PerisMain.java

@Override
public final boolean onCreateOptionsMenu(final Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);
    final MenuItem searchMenuItem = menu.findItem(R.id.search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

    if (this.serverUserid == null || !getString(R.string.subforum_id).contentEquals("0")) {
        searchView.setVisibility(View.GONE);
    } else {/*from  w ww. j  a va 2s . co m*/
        if (ThemeSetter.getForegroundDark(this.background)) {
            searchMenuItem.setIcon(R.drawable.ic_action_search_dark);
        }
    }

    searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
        public void onFocusChange(final View view, final boolean queryTextFocused) {
            if (!queryTextFocused) {
                searchMenuItem.collapseActionView();
                searchView.setQuery("", false);
            }
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        public boolean onQueryTextChange(final String newText) {
            // TODO Auto-generated method stub
            return false;
        }

        @SuppressWarnings("checkstyle:requirethis")
        public boolean onQueryTextSubmit(final String query) {
            if (getActionBar() != null) {
                getActionBar().setSubtitle(baseSubtitle);
            }
            searchMenuItem.collapseActionView();
            searchView.setQuery("", false);

            final Bundle bundle = new Bundle();
            bundle.putString("subforum_name", (String) "Search - " + query);
            bundle.putString("subforum_id", (String) "search");
            bundle.putString("query", (String) query);
            bundle.putString("background", (String) background);
            bundle.putString("icon", (String) "n/a");
            bundle.putString("inTab", (String) "N");
            loadCategory(bundle, "SEARCH_QUERY", false);

            return false;
        }
    });
    return true;
}