Source:
private void showSearchBoxLayout() { mSearchBox = mInflater.inflate(R.layout.searchview, null); navButton = mSearchBox.findViewById(R.id.btn_nav_menu); mDrawerLayout = getActivity().findViewById(R.id.maps_app_activity_drawer_layout); mDrawerList = getActivity().findViewById(R.id.maps_app_activity_left_drawer); navButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mDrawerLayout.isDrawerOpen(mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } }); mSearchBox.setLayoutParams(mlayoutParams); mSearchview = mSearchBox.findViewById(R.id.searchView1); ImageView iv_route = mSearchBox.findViewById(R.id.imageView1); mSearchview.setIconifiedByDefault(false); mSearchview.setQueryHint(SEARCH_HINT); applySuggestionCursor(); mMapContainer.addView(mSearchBox); iv_route.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showRoutingDialogFragment(); } }); mSearchview.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { onSearchButtonClicked(query); mSearchview.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { if (mLocator == null) return false; getSuggestions(newText); return true; } }); mSearchBox.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { addCompass(mSearchBox.getHeight()); mSearchBox.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); mSearchview.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { MatrixCursor cursor = (MatrixCursor) mSearchview.getSuggestionsAdapter().getItem(position); int indexColumnSuggestion = cursor.getColumnIndex(COLUMN_NAME_ADDRESS); final String address = cursor.getString(indexColumnSuggestion); geoCodeSuggestedLocation(address); cursor.close(); return true; } }); }

Target:
private void showSearchBoxLayout() { mSearchBox = mInflater.inflate(R.layout.searchview, null); mNavButton = mSearchBox.findViewById(R.id.btn_nav_menu); mDrawerLayout = getActivity().findViewById(R.id.maps_app_activity_drawer_layout); mDrawerList = getActivity().findViewById(R.id.maps_app_activity_left_drawer); mNavButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mDrawerLayout.isDrawerOpen(mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } }); mSearchBox.setLayoutParams(mlayoutParams); mSearchview = mSearchBox.findViewById(R.id.searchView1); ImageView ivRoute = mSearchBox.findViewById(R.id.imageView1); mSearchview.setIconifiedByDefault(false); mSearchview.setQueryHint(SEARCH_HINT); applySuggestionCursor(); mMapContainer.addView(mSearchBox); ivRoute.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showRoutingDialogFragment(); } }); mSearchview.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { onSearchButtonClicked(query); mSearchview.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { if (mLocator == null) return false; getSuggestions(newText); return true; } }); mSearchBox.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { addCompass(mSearchBox.getHeight()); mSearchBox.getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); mSearchview.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { MatrixCursor cursor = (MatrixCursor) mSearchview.getSuggestionsAdapter().getItem(position); int indexColumnSuggestion = cursor.getColumnIndex(COLUMN_NAME_ADDRESS); final String address = cursor.getString(indexColumnSuggestion); geoCodeSuggestedLocation(address); cursor.close(); return true; } }); }