How to filter a RecyclerView with a SearchView

Introduction Since it is not really clear from your question what exactly you are having trouble with, I wrote up this quick walkthrough about how to implement this feature; if you still have questions feel free to ask. I have a working example of everything I am talking about here in this GitHub Repository. In … Read more

How to update RecyclerView Adapter Data

This is a general answer. The various ways to update the adapter data are explained. The process includes two main steps every time: Update the data set Notify the adapter of the change Insert single item Add “Pig” at index 2. String item = “Pig”; int insertIndex = 2; data.add(insertIndex, item); adapter.notifyItemInserted(insertIndex); Insert multiple items … Read more

How to implement endless list with RecyclerView?

Thanks to @Kushal and this is how I implemented it private boolean loading = true; int pastVisiblesItems, visibleItemCount, totalItemCount; mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { if (dy > 0) { //check for scroll down visibleItemCount = mLayoutManager.getChildCount(); totalItemCount = mLayoutManager.getItemCount(); pastVisiblesItems = mLayoutManager.findFirstVisibleItemPosition(); if (loading) { if ((visibleItemCount … Read more

How to build a horizontal ListView with RecyclerView

Is there a better way to implement this now with RecyclerView now? Yes. When you use a RecyclerView, you need to specify a LayoutManager that is responsible for laying out each item in the view. The LinearLayoutManager allows you to specify an orientation, just like a normal LinearLayout would. To create a horizontal list with … Read more

RecyclerView onClick

Here is a better and less tightly coupled way to implement an OnClickListener for a RecyclerView. Snippet of usage: RecyclerView recyclerView = findViewById(R.id.recycler); recyclerView.addOnItemTouchListener( new RecyclerItemClickListener(context, recyclerView ,new RecyclerItemClickListener.OnItemClickListener() { @Override public void onItemClick(View view, int position) { // do whatever } @Override public void onLongItemClick(View view, int position) { // do whatever } }) … Read more

How to create RecyclerView with multiple view types

Yes, it’s possible. Just implement getItemViewType(), and take care of the viewType parameter in onCreateViewHolder(). So you do something like: public class MyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { class ViewHolder0 extends RecyclerView.ViewHolder { … public ViewHolder0(View itemView){ … } } class ViewHolder2 extends RecyclerView.ViewHolder { … public ViewHolder2(View itemView){ … } @Override public int getItemViewType(int position) { … Read more

Why doesn’t RecyclerView have onItemClickListener()?

tl;dr 2016 Use RxJava and a PublishSubject to expose an Observable for the clicks. public class ReactiveAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> { String[] mDataset = { “Data”, “In”, “Adapter” }; private final PublishSubject<String> onClickSubject = PublishSubject.create(); @Override public void onBindViewHolder(final ViewHolder holder, int position) { final String element = mDataset[position]; holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View … Read more

How to add dividers and spaces between items in RecyclerView

October 2016 Update The version 25.0.0 of Android Support Library introduced the DividerItemDecoration class: DividerItemDecoration is a RecyclerView.ItemDecoration that can be used as a divider between items of a LinearLayoutManager. It supports both HORIZONTAL and VERTICAL orientations. Usage: DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(), layoutManager.getOrientation()); recyclerView.addItemDecoration(dividerItemDecoration); Previous answer Some answers either use methods that have since … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)