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);
}
Aggregations