Add a search filter on RecyclerView with Cards?

Yes it is possible Your RecyclerView.Adapter can implement Filterable. After that you have to override Filter getFilter() method. You have to define your own filter as is shown in the code below: @Override public Filter getFilter() { return new YourFilterClass(); } YourFilterClass class YourFilterClass extends Filter { @Override protected FilterResults performFiltering(CharSequence constraint) { //Here you … Read more

MenuItemCompat.getActionView always returns null

Finally I found the solution. Changing namespace of actionViewClass from android:actionViewClass to app:actionViewClass Implementing android.support.v7.widget.SearchView.OnQueryTextListener interface for current activity. Directly use setOnQueryTextListener instead of SearchViewCompat.setOnQueryTextListener @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.menu, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView != null) { searchView.setOnQueryTextListener(this); } return super.onCreateOptionsMenu(menu); … Read more

How can we have searched characters colored when we use searchview in recyclerview?

After a hard effort I found the answer myself. I use a function like this: fun colorsearch(a:String,charText: String):SpannableStringBuilder{ var l = 0 var b:ArrayList<Int> b = ArrayList() var w = 0 var i = 0 if (charText!=””){ label@ while (i < a.length) { var j=0 while (j<charText.length){ Log.v(“abc”, j.toString()) if (i == a.length) break@label while … Read more

Creating a SearchView that looks like the material design guidelines

It is actually quite easy to do this, if you are using android.support.v7 library. Step – 1 Declare a menu item <item android:id=”@+id/action_search” android:title=”Search” android:icon=”@drawable/abc_ic_search_api_mtrl_alpha” app:showAsAction=”ifRoom|collapseActionView” app:actionViewClass=”android.support.v7.widget.SearchView” /> Step – 2 Extend AppCompatActivity and in the onCreateOptionsMenu setup the SearchView. import android.support.v7.widget.SearchView; … public class YourActivity extends AppCompatActivity { … @Override public boolean onCreateOptionsMenu(Menu menu) … Read more

Is it possible to change the textcolor on an Android SearchView?

Add <item name=”android:editTextColor”>@android:color/white</item> to the parent theme and that should change the entered text. You can also use <item name=”android:textColorHint”>@android:color/white</item> to change the hint text color for the SearchView. (Note that you can replace the @android:color/white with whatever appropriate value you’re hoping to use)

Android – NullPointerException on SearchView in Action Bar

Try to replace the failing line with: mSearchMenuItem = menu.findItem(R.id.action_search); mSearchView = (EnglishVerbSearchView) MenuItemCompat.getActionView(mSearchMenuItem); Where R.id.action_search is the id of your search item in the menu. EDIT Your manifest should look like that: <activity android:name=”com.bronzelabs.twc.activities.WorkflowListActivity” android:label=”@string/app_name” android:theme=”@style/Theme.AppCompat.Light” > <intent-filter> <action android:name=”android.intent.action.MAIN” /> <category android:name=”android.intent.category.LAUNCHER” /> </intent-filter> </activity> <activity android:name=”.activities.SearchResultActivity” android:theme=”@style/Theme.AppCompat.Light” android:launchMode=”singleTop”> <intent-filter> <action android:name=”android.intent.action.SEARCH” /> … Read more

SearchView In ListView having a custom Adapter

Try this way,hope this will help you… activity_main.xml <SearchView android:id=”@+id/searchView1″ android:layout_width=”match_parent” android:layout_height=”wrap_content”/> <ListView android:id=”@+id/listView1″ android:layout_width=”match_parent” android:layout_height=”0dp” android:layout_weight=”1″/> </LinearLayout> row.xml <?xml version=”1.0″ encoding=”utf-8″?> <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” android:orientation=”vertical” android:layout_width=”match_parent” android:layout_height=”match_parent”> <TextView android:id=”@+id/txtName” android:layout_width=”wrap_content” android:layout_height=”wrap_content” /> <TextView android:id=”@+id/txtAge” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_marginTop=”5dp”/> </LinearLayout> MainActivity.java public class MainActivity extends Activity implements SearchView.OnQueryTextListener { private SearchView mSearchView; private ListView mListView; private ArrayList<Employee> … Read more

How to use SearchView in Toolbar Android

You have to use Appcompat library for that. Which is used like below: dashboard.xml <menu xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” xmlns:app=”http://schemas.android.com/apk/res-auto”> <item android:id=”@+id/action_search” android:icon=”@android:drawable/ic_menu_search” app:showAsAction=”always|collapseActionView” app:actionViewClass=”androidx.appcompat.widget.SearchView” android:title=”Search”/> </menu> Activity file (in Java): public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.dashboard, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE); SearchView searchView = null; if (searchItem … Read more