#SearchView.OnQueryTextListener
Explore tagged Tumblr posts
Text
SearchView Suggestions over Network in Android
SearchView Suggestions over Network in Android
Hello Friends, Today we’ll see an example of SearchView Suggestions over Network in Android. And there will be two part of this code one will be server side code in PHP and another one Androidapp code. Actually I was working on an android app in which I was required to add search suggestion over network feature in that, So now I am sharing this sample code almost same as I have developed for the…
View On WordPress
0 notes
Text
first we need inflate the menulist to fragment or activity and then we call onOptionsItemSelected for normal menu item or we can call setOnQueryTextListener to search icon in toolbar make sure your Activity or Fragment should need to implement SearchView.OnQueryTextListener and its methods as shown in below code
Here is the java code
@Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.main_right_menu, menu); MenuItem item = menu.findItem(R.id.menu_search); SearchView sv = (SearchView) item.getActionView(); if (sv != null){ sv.setSubmitButtonEnabled(true); sv.setOnQueryTextListener(this); } super.onCreateOptionsMenu(menu, inflater); } @Override public boolean onQueryTextSubmit(String query) { Log.e("Tag",query); return false; } @Override public boolean onQueryTextChange(String newText) { Log.e("Tag",newText); return false; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle item selection switch (item.getItemId()) { case R.id.menu_filter: showFilterOptions(); return true; default: return true; } } private void showFilterOptions() { final Dialog dialog = new Dialog(activity); dialog.setTitle("Filter By"); dialog.setContentView(R.layout.customer_filter); dialog.show(); }
Here is my xml resource menu file orderInCategory refers that menu item has to shown in tool bar as in below images or toolbar dots menu, here i set its value to 1,that means it will visible in toolbar at right side actionViewClass class refers which action class should call by clicking the menuitem
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"> <item android:icon="@drawable/ic_filter_list_white_24dp" android:id="@+id/menu_filter" android:orderInCategory="1" app:showAsAction="always" android:title="@string/filter"/> <item app:showAsAction="ifRoom|collapseActionView" android:icon="@drawable/ic_search_white_24dp" android:id="@+id/menu_search" android:orderInCategory="1" app:actionViewClass="android.support.v7.widget.SearchView" android:title="@string/search" android:iconifiedByDefault="true"/> </menu>
#gallery-0-5 { margin: auto; } #gallery-0-5 .gallery-item { float: left; margin-top: 10px; text-align: center; width: 50%; } #gallery-0-5 img { border: 2px solid #cfcfcf; } #gallery-0-5 .gallery-caption { margin-left: 0; } /* see gallery_shortcode() in wp-includes/media.php */
toolbar search menu in fragment
toolbar search menu in fragment
Android toolbar Menu with search in fragment first we need inflate the menulist to fragment or activity and then we call onOptionsItemSelected for normal menu item or we can call setOnQueryTextListener to search icon in toolbar…
0 notes