androidx.appcompat.widget.SearchView Java Examples

The following examples show how to use androidx.appcompat.widget.SearchView. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MainActivity.java    From Shelter with Do What The F*ck You Want To Public License 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_menu, menu);

    // Initialize the search button
    SearchView searchView = (SearchView) menu.findItem(R.id.main_menu_search).getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            Intent intent = new Intent(BROADCAST_SEARCH_FILTER_CHANGED);
            intent.putExtra("text", newText.toLowerCase().trim());
            LocalBroadcastManager.getInstance(MainActivity.this)
                    .sendBroadcast(intent);
            return true;
        }
    });
    return true;
}
 
Example #2
Source File: SearchFragment.java    From Jockey with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.activity_search, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_library_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mViewModel.setSearchQuery(newText);
            return true;
        }
    });

    searchView.setIconified(false);
    if (!StringUtils.isEmpty(mViewModel.getSearchQuery())) {
        searchView.setQuery(mViewModel.getSearchQuery(), true);
    }
}
 
Example #3
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.hadis, menu);

    mSwitch = menu.findItem(R.id.favswitch);
    mFav = menu.findItem(R.id.fav);
    setCurrentPage(mPager.getCurrentItem());

    MenuItem item = menu.findItem(R.id.menu_item_share);
    item.setOnMenuItemClickListener(item1 -> {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, mShareText);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share)));
        return true;
    });

    item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}
 
Example #4
Source File: ConversationActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    showActionBar();
    //return false;
    getMenuInflater().inflate(R.menu.mobicom_basic_menu_for_normal_message, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    if (Utils.hasICS()) {
        searchItem.collapseActionView();
    }
    searchView.setOnQueryTextListener(this);
    searchView.setSubmitButtonEnabled(true);
    searchView.setIconifiedByDefault(true);

    if (quickConversationFragment != null && !TextUtils.isEmpty(quickConversationFragment.getSearchString())) {
        searchView.setIconified(false);
        searchView.setQuery(quickConversationFragment.getSearchString(), false);
    }

    return super.onCreateOptionsMenu(menu);
}
 
Example #5
Source File: SourceDebugActivity.java    From a with GNU General Public License v3.0 6 votes vote down vote up
private void initSearchView() {
    searchView.setQueryHint(getString(R.string.debug_hint));
    searchView.onActionViewExpanded();
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (TextUtils.isEmpty(query))
                return false;
            startDebug(query);
            SoftInputUtil.hideIMM(searchView);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
}
 
Example #6
Source File: MultiSelectedActionModeCallback.java    From nextcloud-notes with GNU General Public License v3.0 6 votes vote down vote up
public MultiSelectedActionModeCallback(
        Context context, ViewProvider viewProvider, NotesDatabase db, long currentLocalAccountId, boolean canMoveNoteToAnotherAccounts, ItemAdapter adapter, RecyclerView recyclerView, Runnable refreshLists, FragmentManager fragmentManager, SearchView searchView) {
    this.context = context;
    this.viewProvider = viewProvider;
    this.db = db;
    this.currentLocalAccountId = currentLocalAccountId;
    this.canMoveNoteToAnotherAccounts = canMoveNoteToAnotherAccounts;
    this.adapter = adapter;
    this.recyclerView = recyclerView;
    this.refreshLists = refreshLists;
    this.fragmentManager = fragmentManager;
    this.searchView = searchView;

    final TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorAccent, typedValue, true);
    colorAccent = typedValue.data;
}
 
Example #7
Source File: OverviewFragment.java    From kolabnotes-android with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Set up the search view with OnQueryTextListener()
 *
 * @param searchView the search view which need to be set up
 */
private void setUpSearchView(final SearchView searchView) {
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            searchNotes(query);
            // Submit the search will hide the keyboard
            searchView.clearFocus();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Apply the filter when the text is changing
            searchNotes(newText);
            return true;
        }
    });
    searchView.setQueryHint(getString(R.string.dialog_input_text_search_hint));
}
 
Example #8
Source File: DNSServersAdapter.java    From InviZible with GNU General Public License v3.0 6 votes vote down vote up
DNSServersAdapter(Context context, SearchView searchDNSServer,
                  PreferencesDNSCryptServers preferencesDNSCryptServers,
                  FragmentManager fragmentManager,
                  ArrayList<DNSServerItem> list_dns_servers,
                  ArrayList<DNSServerItem> list_dns_servers_saved,
                  ArrayList<DNSServerRelays> routes_current, boolean relaysMdExist) {
    this.context = context;
    this.searchDNSServer = searchDNSServer;
    this.preferencesDNSCryptServers = preferencesDNSCryptServers;
    this.fragmentManager = fragmentManager;
    this.list_dns_servers = list_dns_servers;
    this.list_dns_servers_saved = list_dns_servers_saved;
    this.routes_current = routes_current;
    this.relaysMdExist = relaysMdExist;

    lInflater = (LayoutInflater) Objects.requireNonNull(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
 
Example #9
Source File: HadithFragment.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MaterialMenuInflater.with(getActivity(), inflater)
            .setDefaultColorResource(R.color.white)
            .inflate(R.menu.hadis, menu);

    mSwitch = menu.findItem(R.id.favswitch);
    mFav = menu.findItem(R.id.fav);
    setCurrentPage(mPager.getCurrentItem());

    MenuItem item = menu.findItem(R.id.menu_item_share);
    item.setOnMenuItemClickListener(item1 -> {
        Intent sendIntent = new Intent();
        sendIntent.setAction(Intent.ACTION_SEND);
        sendIntent.putExtra(Intent.EXTRA_TEXT, mShareText);
        sendIntent.setType("text/plain");
        startActivity(Intent.createChooser(sendIntent, getResources().getText(R.string.share)));
        return true;
    });

    item = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);

    searchView.setOnQueryTextListener(this);
}
 
Example #10
Source File: ModulesFragment.java    From EdXposedManager with GNU General Public License v3.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.list_fragment, container, false);

    mListView = view.findViewById(android.R.id.list);

    mBackgroundList = view.findViewById(R.id.background_list);
    ((ImageView) view.findViewById(R.id.background_list_iv)).setImageResource(R.drawable.ic_nav_modules);
    ((TextView) view.findViewById(R.id.list_status)).setText(R.string.no_xposed_modules_found);

    mSearchListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            filter(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            filter(newText);
            return false;
        }
    };
    return view;
}
 
Example #11
Source File: BookSourceActivity.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
private void initSearchView() {
    AppCompat.useCustomIconForSearchView(searchView, getResources().getString(R.string.search_book_source));
    mSearchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchView.onActionViewExpanded();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            isSearch = !TextUtils.isEmpty(newText);
            mPresenter.refresh();
            return false;
        }
    });

    searchView.post(()->searchView.clearFocus());
}
 
Example #12
Source File: FavoriteActivityTest.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Test
public void testSearchView() {
    SearchView searchView = (SearchView) actionViewResolver.getActionView(mock(MenuItem.class));
    verify(searchView, atLeastOnce()).setOnSearchClickListener(searchViewClickListener.capture());
    verify(searchView, atLeastOnce()).setOnCloseListener(searchViewCloseListener.capture());
    searchViewClickListener.getAllValues()
            .get(searchViewClickListener.getAllValues().size() - 1)
            .onClick(searchView);
    assertFalse(((FavoriteFragment) fragment).startActionMode(null));
    SearchView.OnCloseListener closeListener = searchViewCloseListener.getAllValues()
            .get(searchViewCloseListener.getAllValues().size() - 1);
    closeListener.onClose();
    assertEquals(2, adapter.getItemCount());
    ((FavoriteFragment) fragment).filter("ask");
    verify(favoriteManager, times(2)).attach(observerCaptor.capture(), any());
    when(favoriteManager.getSize()).thenReturn(1);
    when(favoriteManager.getItem(eq(0))).thenReturn(new TestFavorite(
            "2", "http://example.com", "ask HN", System.currentTimeMillis()));
    observerCaptor.getValue().onChanged();
    assertEquals(1, adapter.getItemCount());
    reset(searchView);
    closeListener.onClose();
    verify(searchView).setQuery(eq(FavoriteActivity.EMPTY_QUERY), eq(true));
}
 
Example #13
Source File: BaseListActivity.java    From materialistic with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mIsMultiPane) {
        getMenuInflater().inflate(R.menu.menu_item_compact, menu);
    }
    if (isSearchable()) {
        getMenuInflater().inflate(R.menu.menu_search, menu);
        MenuItem menuSearch = menu.findItem(R.id.menu_search);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(
                new ComponentName(this, SearchActivity.class)));
        searchView.setIconified(true);
        searchView.setQuery("", false);
    }
    return super.onCreateOptionsMenu(menu);
}
 
Example #14
Source File: SearchBookActivity.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
private void initSearchView() {
    AppCompat.useSimpleStyleForSearchView(searchView, getString(R.string.searchBook));
    mSearchAutoComplete = searchView.findViewById(R.id.search_src_text);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            toSearch();
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            mPresenter.querySearchHistory(newText);
            return false;
        }
    });

    searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
        if (hasFocus) {
            mPresenter.stopSearch();
            openOrCloseHistory(true);
        }
    });
}
 
Example #15
Source File: SubsonicFragment.java    From Audinaut with GNU General Public License v3.0 6 votes vote down vote up
void onFinishSetupOptionsMenu(final Menu menu) {
    searchItem = menu.findItem(R.id.menu_global_search);
    if (searchItem != null) {
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);
        SearchableInfo searchableInfo = searchManager.getSearchableInfo(context.getComponentName());
        if (searchableInfo == null) {
            Log.w(TAG, "Failed to get SearchableInfo");
        } else {
            searchView.setSearchableInfo(searchableInfo);
        }

        String currentQuery = getCurrentQuery();
        if (currentQuery != null) {
            searchView.setOnSearchClickListener(v -> searchView.setQuery(getCurrentQuery(), false));
        }
    }
}
 
Example #16
Source File: BookSourceActivity.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private void initSearchView() {
    mSearchAutoComplete = searchView.findViewById(R.id.search_src_text);
    mSearchAutoComplete.setTextSize(16);
    searchView.setQueryHint(getString(R.string.search_book_source));
    searchView.onActionViewExpanded();
    searchView.clearFocus();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            isSearch = !TextUtils.isEmpty(newText);
            refreshBookSource();
            return false;
        }
    });
}
 
Example #17
Source File: SourceDebugActivity.java    From MyBookshelf with GNU General Public License v3.0 6 votes vote down vote up
private void initSearchView() {
    searchView.setQueryHint(getString(R.string.debug_hint));
    searchView.onActionViewExpanded();
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (TextUtils.isEmpty(query))
                return false;
            startDebug(query);
            SoftInputUtil.hideIMM(searchView);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
}
 
Example #18
Source File: AppBlockFragment.java    From XposedSmsCode with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_app_block, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            doFilter(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            doFilter(newText);
            return true;
        }
    });
}
 
Example #19
Source File: MainActivity.java    From arcgis-runtime-samples-android with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  getMenuInflater().inflate(R.menu.search_menu, menu);
  MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
  SearchView searchView = (SearchView) myActionMenuItem.getActionView();
  searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
    @Override
    public boolean onQueryTextSubmit(String query) {
      search(query);
      if (!searchView.isIconified()) {
        searchView.setIconified(true);
      }
      myActionMenuItem.collapseActionView();
      return false;
    }

    @Override
    public boolean onQueryTextChange(String s) {
      return false;
    }
  });
  return true;
}
 
Example #20
Source File: ChapterDrawerFragment.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
private void inflateMenu() {
    toolbar.inflateMenu(R.menu.menu_search_view);
    MenuItem search = toolbar.getMenu().findItem(R.id.action_search);
    searchView = (SearchView) search.getActionView();
    AppCompat.useCustomIconForSearchView(searchView, getResources().getString(R.string.search));
    searchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels);
    searchView.onActionViewCollapsed();
    searchView.setOnCloseListener(() -> {
        tabLayout.setVisibility(VISIBLE);
        return false;
    });
    searchView.setOnSearchClickListener(view -> tabLayout.setVisibility(GONE));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            int tab = tabLayout.getSelectedTabPosition();
            fragments[tab].getFilter().filter(newText);
            return false;
        }
    });
}
 
Example #21
Source File: SourceDebugActivity.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
private void initSearchView() {
    AppCompat.useCustomIconForSearchView(searchView, getString(R.string.debug_hint));
    searchView.onActionViewExpanded();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (TextUtils.isEmpty(query))
                return false;
            startDebug(query);
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
}
 
Example #22
Source File: MainActivity.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void initializeSearchItem(MenuItem item) {
    if(modeType != ModeType.FAVORITE)
        item.setActionView(null);
    else{
        ((SearchView) item.getActionView()).setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                inspector=InspectorV3.favoriteInspector(MainActivity.this,query,1,resetDataset);
                inspector.start();
                getSupportActionBar().setTitle(query);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                return false;
            }
        });
    }
}
 
Example #23
Source File: TagFilterActivity.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_tag_filter, menu);
    updateSortItem(menu.findItem(R.id.sort_by_name));
    searchView=(androidx.appcompat.widget.SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setOnQueryTextListener(new androidx.appcompat.widget.SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            Fragment page = getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.container + ":" + mViewPager.getCurrentItem());
            if (page != null) {
                ((TagTypePage)page).refilter(newText);
            }
            return true;
        }
    });
    return true;
}
 
Example #24
Source File: FavoriteFragment.java    From materialistic with Apache License 2.0 6 votes vote down vote up
private void createSearchView(MenuItem menuSearch) {
    final SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
    searchView.setQueryHint(getString(R.string.hint_search_saved_stories));
    searchView.setSearchableInfo(((SearchManager) getActivity()
            .getSystemService(Context.SEARCH_SERVICE))
            .getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconified(!mSearchViewExpanded);
    searchView.setQuery(mFilter, false);
    searchView.setOnSearchClickListener(v -> {
        mSearchViewExpanded = true;
        v.requestFocus();
    });
    searchView.setOnCloseListener(() -> {
        // trigger a dummy empty search intent, as empty query does not get submitted
        searchView.setQuery(FavoriteActivity.EMPTY_QUERY, true);
        return false;
    });
}
 
Example #25
Source File: SmsDragListActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
@Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.draglist_menu, menu);

        final MenuItem searchItem = menu.findItem(R.id.action_search);
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            /**
             * Not sense doing via android.widget.Filter as adapter and its data is filtered in async mode 
             */
            @Override
            public boolean onQueryTextChange(String newText) {
                cursorSource.setConstraint(newText);
                adapter.reloadAsyncSource();
                
                if (!StringUtil.isEmpty(newText)) {
                    Log.i(TAG, "filtered by `" + newText + "`");
//                    Toast.makeText(SmsDragListActivity.this, "filtered by '" + newText + "'", Toast.LENGTH_SHORT).show();
                }
                return true;
            }
        });

        final MenuItem newItem = menu.findItem(R.id.new_sms_template);
        newItem.setOnMenuItemClickListener(this::addItem);
        return true;
    }
 
Example #26
Source File: FilesFragment.java    From odyssey with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initialize the options menu.
 * Be sure to call {@link #setHasOptionsMenu} before.
 *
 * @param menu         The container for the custom options menu.
 * @param menuInflater The inflater to instantiate the layout.
 */
@Override
public void onCreateOptionsMenu(@NonNull Menu menu, @NonNull MenuInflater menuInflater) {
    // Inflate the menu; this adds items to the action bar if it is present.
    menuInflater.inflate(R.menu.options_menu_files_fragment, menu);

    // get tint color
    int tintColor = ThemeUtils.getThemeColor(getContext(), R.attr.odyssey_color_text_accent);

    Drawable drawable = menu.findItem(R.id.action_search).getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, tintColor);
    menu.findItem(R.id.action_search).setIcon(drawable);

    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();

    // Check if a search string is saved from before
    if (mSearchString != null) {
        // Expand the view
        searchView.setIconified(false);
        menu.findItem(R.id.action_search).expandActionView();
        // Set the query string
        searchView.setQuery(mSearchString, false);
        // Notify the adapter
        applyFilter(mSearchString);
    }

    searchView.setOnQueryTextListener(new SearchTextObserver());

    super.onCreateOptionsMenu(menu, menuInflater);
}
 
Example #27
Source File: GamesFragment.java    From UpdogFarmer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_games, menu);
    final MenuItem searchItem = menu.findItem(R.id.search);
    searchView = (SearchView) searchItem.getActionView();
    searchView.setOnQueryTextListener(this);
    super.onCreateOptionsMenu(menu, inflater);
}
 
Example #28
Source File: MainActivity.java    From Status with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);

    resetItem = menu.findItem(R.id.action_reset);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            adapter.filter(viewPager.getCurrentItem(), query.toLowerCase());
            appbar.setExpanded(true);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            adapter.filter(viewPager.getCurrentItem(), newText.toLowerCase());
            appbar.setExpanded(true);
            return true;
        }
    });

    searchView.setOnCloseListener(() -> {
        adapter.filter(viewPager.getCurrentItem(), null);
        return false;
    });

    return super.onCreateOptionsMenu(menu);
}
 
Example #29
Source File: Example7Fragment.java    From SectionedRecyclerViewAdapter with MIT License 5 votes vote down vote up
@Override
public void onCreateOptionsMenu(@NonNull final Menu menu, @NonNull final MenuInflater inflater) {
    inflater.inflate(R.menu.menu_ex7, menu);

    final MenuItem item = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) item.getActionView();
    searchView.setOnQueryTextListener(this);
}
 
Example #30
Source File: SelectFileActivity.java    From turbo-editor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_select_file, menu);
    mSearchViewMenuItem = menu.findItem(R.id.im_search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(mSearchViewMenuItem);
    mSearchView.setIconifiedByDefault(true);
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setSubmitButtonEnabled(false);
    return super.onCreateOptionsMenu(menu);
}