private void performShowOptions() { final ListPopupWindow popupWindow = new ListPopupWindow(this); ArrayList<String> values = new ArrayList<>( Arrays.asList(getResources().getStringArray(R.array.search_options_labels))); String value = values.get(mCurrentOption); SimpleDropDownAdapter<Integer> adapter = new SimpleDropDownAdapter<>(this, values, values, mIcons, value); popupWindow.setAnchorView(mBinding.anchor); popupWindow.setDropDownGravity(GravityCompat.END); popupWindow.setAdapter(adapter); popupWindow.setContentWidth(adapter.measureContentWidth()); popupWindow.setOnItemClickListener((parent, view, position, id) -> { popupWindow.dismiss(); mCurrentOption = position; Preferences.setAccountSearchMode(this, mAccount, mCurrentOption); configureSearchHint(); mBinding.searchView.setCustomIcon(ContextCompat.getDrawable(this, mIcons[position])); clearSuggestions(); mHandler.removeMessages(FETCH_SUGGESTIONS_MESSAGE); mHandler.removeMessages(SHOW_HISTORY_MESSAGE); final Message msg = Message.obtain(mHandler, SHOW_HISTORY_MESSAGE); mHandler.sendMessageDelayed(msg, 500L); }); popupWindow.setModal(true); popupWindow.show(); }