Search in sources :

Example 1 with OnQueryTextListener

use of android.widget.SearchView.OnQueryTextListener in project bitcoin-wallet by bitcoin-wallet.

the class ExchangeRatesFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(final Menu menu, final MenuInflater inflater) {
    inflater.inflate(R.menu.exchange_rates_fragment_options, menu);
    final MenuItem searchMenuItem = menu.findItem(R.id.exchange_rates_options_search);
    if (Constants.ENABLE_EXCHANGE_RATES) {
        final SearchView searchView = (SearchView) searchMenuItem.getActionView();
        searchView.setOnQueryTextListener(new OnQueryTextListener() {

            @Override
            public boolean onQueryTextChange(final String newText) {
                query = Strings.emptyToNull(newText.trim());
                getLoaderManager().restartLoader(ID_RATE_LOADER, null, rateLoaderCallbacks);
                return true;
            }

            @Override
            public boolean onQueryTextSubmit(final String query) {
                searchView.clearFocus();
                return true;
            }
        });
        // Workaround for not being able to style the SearchView
        final int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        final View searchInput = searchView.findViewById(id);
        if (searchInput instanceof EditText)
            ((EditText) searchInput).setTextColor(Color.WHITE);
    } else {
        searchMenuItem.setVisible(false);
    }
    super.onCreateOptionsMenu(menu, inflater);
}
Also used : EditText(android.widget.EditText) OnQueryTextListener(android.widget.SearchView.OnQueryTextListener) SearchView(android.widget.SearchView) MenuItem(android.view.MenuItem) View(android.view.View) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 EditText (android.widget.EditText)1 SearchView (android.widget.SearchView)1 OnQueryTextListener (android.widget.SearchView.OnQueryTextListener)1 TextView (android.widget.TextView)1