{"id":6028,"date":"2020-06-04T15:53:35","date_gmt":"2020-06-04T10:23:35","guid":{"rendered":"https:\/\/www.innovationm.com\/blog\/?p=6028"},"modified":"2023-01-20T18:55:20","modified_gmt":"2023-01-20T13:25:20","slug":"custom-filterable-adapter","status":"publish","type":"post","link":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/","title":{"rendered":"Custom &#038; Filterable Adapter"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">Code optimization is one of the most core features of a good developer. As far as Android developers are concerned the better the optimised code the better is the performance.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Every time creating a new separate class for each adapter for a simple RecyclerView makes the code redundant.\u00a0<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create a new adapter class\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Extend with RecyclerView.Adapter<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create another new class<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Extend with RecyclerView.ViewHolder<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Write logic in onBindView<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Except for the point no. 5 all steps are repeatable, that means with every new adapter we need to write codes for all points. So, a Custom Adapter can find a way for this where all points except 5 will be common for all and 5th point will be overridden to write your logic.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">CustomAdapter is a generic adapter abstract class which will optimize code and avoid writing redundant code.\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">CustomAdapter extends RecyclerView.Adapter and has its own ViewHolder class extending RecyclerView.ViewHolder name as ItemViewHolder.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">CustomAdapter has a generic type enclosed in anchor bracket &lt;T&gt; which represents what type of data it will hold and show as a list. For example, data can be a list of Car as ArrayList&lt;Car&gt; cars, list of Person as ArrayList&lt;Person&gt;. So &lt;T&gt; here represents &lt;Car&gt;, &lt;Person&gt; etc<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">CustomAdapter also takes layout resource id as a constructor on how the items will be mapped from the list of data in UI.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">In this class, bindView is an abstract class to fulfil above point no. 5. To write your business logic.<\/span><\/li>\n<\/ol>\n<pre class=\"lang:default decode:true\">abstract class CustomAdapter&lt;T&gt;(\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private val layoutResId : Int,\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0private var mList : ArrayList&lt;T&gt;\r\n\r\n) : androidx.recyclerview.widget.RecyclerView.Adapter&lt;ItemViewHolder&gt;() {\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0viewBinder(holder, mList[position], position)\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val view : View = LayoutInflater.from(parent.context)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0.inflate(layoutResId, parent, false)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return ItemViewHolder(view)\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\r\n\u00a0\u00a0\u00a0override fun getItemCount(): Int = mList.size\r\n\r\n\r\n\u00a0\u00a0\u00a0\/\/=============================== unoverriden methods ==================================\r\n\r\n\u00a0\u00a0\u00a0fun setList(list : ArrayList&lt;T&gt;) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList = list\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0fun getList() : ArrayList&lt;T&gt; = this.mList\r\n\r\n\r\n\r\n\u00a0\u00a0\u00a0fun addMoreList(list : ArrayList&lt;T&gt;, isClear: Boolean = false) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (isClear) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.clear()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.addAll(list)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0fun clearList() {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.clear()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0fun addItem(item : T) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.add(item)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0fun removeLastItem() {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (mList.size &gt; 0) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList[mList.size - 1]\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0fun removeItem(item : T) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (mList.isNotEmpty()) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.remove(item)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0fun isListEmpty() : Boolean = mList.isEmpty()\r\n\r\n\u00a0\u00a0\u00a0\/\/================================ abstract methods =====================================\r\n\r\n\u00a0\u00a0\u00a0abstract fun viewBinder(holder: ItemViewHolder, objects : T, position: Int)\r\n\r\n\u00a0\u00a0\u00a0\/\/==================================== private members ========================================\r\n\r\n}\r\nclass ItemViewHolder(view: View) : androidx.recyclerview.widget.RecyclerView.ViewHolder(view)\r\n\r\n<\/pre>\n<p><span style=\"font-weight: 400;\">FilterableAdapter is an extension of the CustomAdapter. In other words, giving extra functionality to CustomAdapter.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are many scenarios where we want to filter the list, in order to achieve this we write full fledged code, performing operations on the list like add, remove clear etc.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The steps goes like :\u00a0<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create new adapter class\u00a0<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Extend with CustomAdapter&lt;T&gt; and Implementing Filterable interface<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create another new class<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Extend with RecyclerView.ViewHolder<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Write logic in onBindView<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create filter class extending Filter class<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Perform the Filter operation on the basis of some filtering predicates like person.age &gt; 50, or person.name.startsWith(\u201cA\u201d) etc.<\/span><\/li>\n<\/ol>\n<p><span style=\"font-weight: 400;\">Same as CustomAdapter, FilterableAdapter will focus on point No. 7 the business logic.<\/span><\/p>\n<ol>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Create an adapter extending FilterableAdapter&lt;T&gt; , T can be any data on which you want to person filtration.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Override performFilterating method which will provide filtration predicate as its parameter and the return type is ArrayList&lt;T&gt; which is a filter list filtered on the basis of filtration predicate from the original list.<\/span><\/li>\n<li style=\"font-weight: 400;\"><span style=\"font-weight: 400;\">Add TextWatcher to search editText and on onTextChange write a line filterableAdapter.getFilter().filter(text). Here filterableAdapter is the object of FilterableAdapter, getFilter is the member method, filter is the member method of Filter class and text is what wrote on editText which we get as parameter in onTextChange method.<\/span><\/li>\n<\/ol>\n<pre class=\"lang:default decode:true \">abstract class FilterableAdapter&lt;T&gt;(\r\n\r\n\u00a0\u00a0\u00a0private var mList : ArrayList&lt;T&gt;,\r\n\r\n\u00a0\u00a0\u00a0private val layoutResId : Int\r\n\r\n) : CustomAdapter&lt;T&gt;(layoutResId, mList), Filterable {\r\n\r\n\u00a0\u00a0\u00a0abstract fun performFiltering(filterationText: String): ArrayList&lt;T&gt;\r\n\r\n\u00a0\u00a0\u00a0override fun getItemCount(): Int = mList.size\r\n\r\n\u00a0\u00a0\u00a0override fun getFilter(): Filter {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (customFilter != null) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.clear()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.addAll(tempList)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (customFilter == null)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0customFilter = CustomFilter()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return customFilter as CustomFilter\r\n\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\/\/====================================== private members =======================================\r\n\r\n\u00a0\u00a0\u00a0private var customFilter : CustomFilter? = null\r\n\r\n\u00a0\u00a0\u00a0private var tempList : ArrayList&lt;T&gt;\r\n\u00a0\u00a0\u00a0init {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0tempList = ArrayList&lt;T&gt;(mList)\r\n\r\n\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0private inner class CustomFilter : Filter() {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0override fun performFiltering(constraint: CharSequence?): FilterResults {\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0val fResult : FilterResults = FilterResults()\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 var filterList : ArrayList&lt;T&gt; = ArrayList()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (constraint != null &amp;&amp; constraint.length &gt; 0) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0filterList = performFiltering(constraint.toString())\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fResult.values = filterList\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fResult.values = mList\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0fResult.count = filterList.size\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return fResult\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0override fun publishResults(constraint: CharSequence?, results: FilterResults?) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.clear()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if (!constraint!!.isEmpty() || results!!.count != 0) {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.addAll(results!!.values as ArrayList&lt;T&gt;)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0} else {\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0mList.addAll(tempList)\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0notifyDataSetChanged()\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0}\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>Thanks for giving your valuable time. Keep reading and keep learning<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Code optimization is one of the most core features of a good developer. As far as Android developers are concerned the better the optimised code the better is the performance. Every time creating a new separate class for each adapter for a simple RecyclerView makes the code redundant.\u00a0 Create a new adapter class\u00a0 Extend with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":6030,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,71],"tags":[],"class_list":["post-6028","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-android","category-mobile"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Custom &amp; Filterable Adapter - InnovationM - Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Custom &amp; Filterable Adapter - InnovationM - Blog\" \/>\n<meta property=\"og:description\" content=\"Code optimization is one of the most core features of a good developer. As far as Android developers are concerned the better the optimised code the better is the performance. Every time creating a new separate class for each adapter for a simple RecyclerView makes the code redundant.\u00a0 Create a new adapter class\u00a0 Extend with [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/\" \/>\n<meta property=\"og:site_name\" content=\"InnovationM - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2020-06-04T10:23:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-01-20T13:25:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2020\/06\/Custom-Adapter.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1141\" \/>\n\t<meta property=\"og:image:height\" content=\"634\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"InnovationM Admin\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"InnovationM Admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/\"},\"author\":{\"name\":\"InnovationM Admin\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"headline\":\"Custom &#038; Filterable Adapter\",\"datePublished\":\"2020-06-04T10:23:35+00:00\",\"dateModified\":\"2023-01-20T13:25:20+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/\"},\"wordCount\":492,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Custom-Adapter.png\",\"articleSection\":[\"Android\",\"Mobile\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/\",\"name\":\"Custom & Filterable Adapter - InnovationM - Blog\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Custom-Adapter.png\",\"datePublished\":\"2020-06-04T10:23:35+00:00\",\"dateModified\":\"2023-01-20T13:25:20+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Custom-Adapter.png\",\"contentUrl\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Custom-Adapter.png\",\"width\":1141,\"height\":634,\"caption\":\"Mobile App development Company UK\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/custom-filterable-adapter\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Custom &#038; Filterable Adapter\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/\",\"name\":\"InnovationM - Blog\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/#\\\/schema\\\/person\\\/a831bf4602d69d1fa452e3de0c8862ed\",\"name\":\"InnovationM Admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g\",\"caption\":\"InnovationM Admin\"},\"sameAs\":[\"http:\\\/\\\/www.innovationm.com\\\/\"],\"url\":\"https:\\\/\\\/www.innovationm.com\\\/blog\\\/author\\\/innovationmadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Custom & Filterable Adapter - InnovationM - Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/","og_locale":"en_US","og_type":"article","og_title":"Custom & Filterable Adapter - InnovationM - Blog","og_description":"Code optimization is one of the most core features of a good developer. As far as Android developers are concerned the better the optimised code the better is the performance. Every time creating a new separate class for each adapter for a simple RecyclerView makes the code redundant.\u00a0 Create a new adapter class\u00a0 Extend with [&hellip;]","og_url":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/","og_site_name":"InnovationM - Blog","article_published_time":"2020-06-04T10:23:35+00:00","article_modified_time":"2023-01-20T13:25:20+00:00","og_image":[{"width":1141,"height":634,"url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2020\/06\/Custom-Adapter.png","type":"image\/png"}],"author":"InnovationM Admin","twitter_misc":{"Written by":"InnovationM Admin","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#article","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/"},"author":{"name":"InnovationM Admin","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"headline":"Custom &#038; Filterable Adapter","datePublished":"2020-06-04T10:23:35+00:00","dateModified":"2023-01-20T13:25:20+00:00","mainEntityOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/"},"wordCount":492,"commentCount":0,"image":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2020\/06\/Custom-Adapter.png","articleSection":["Android","Mobile"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/","url":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/","name":"Custom & Filterable Adapter - InnovationM - Blog","isPartOf":{"@id":"https:\/\/www.innovationm.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#primaryimage"},"image":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#primaryimage"},"thumbnailUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2020\/06\/Custom-Adapter.png","datePublished":"2020-06-04T10:23:35+00:00","dateModified":"2023-01-20T13:25:20+00:00","author":{"@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed"},"breadcrumb":{"@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#primaryimage","url":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2020\/06\/Custom-Adapter.png","contentUrl":"https:\/\/www.innovationm.com\/blog\/wp-content\/uploads\/2020\/06\/Custom-Adapter.png","width":1141,"height":634,"caption":"Mobile App development Company UK"},{"@type":"BreadcrumbList","@id":"https:\/\/www.innovationm.com\/blog\/custom-filterable-adapter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.innovationm.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Custom &#038; Filterable Adapter"}]},{"@type":"WebSite","@id":"https:\/\/www.innovationm.com\/blog\/#website","url":"https:\/\/www.innovationm.com\/blog\/","name":"InnovationM - Blog","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.innovationm.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.innovationm.com\/blog\/#\/schema\/person\/a831bf4602d69d1fa452e3de0c8862ed","name":"InnovationM Admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5c99d9eece9dfbc82297cf34ddd58e9fe05bb52fe66c8f6bf6c0a45bfb6d7629?s=96&r=g","caption":"InnovationM Admin"},"sameAs":["http:\/\/www.innovationm.com\/"],"url":"https:\/\/www.innovationm.com\/blog\/author\/innovationmadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/6028","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/comments?post=6028"}],"version-history":[{"count":0,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/posts\/6028\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media\/6030"}],"wp:attachment":[{"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/media?parent=6028"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/categories?post=6028"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.innovationm.com\/blog\/wp-json\/wp\/v2\/tags?post=6028"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}