Using FastAdapter in Open Event Organizer Android Project

RecyclerView is an important graphical UI component in any android application. Android provides RecyclerView.Adapter class which manages all the functionality of RecyclerView. I don't know why but android people have kept this class in a very abstract form with only basic functionalities implemented by default. On the plus side it opens many doors for custom adapters with new functionalities for example, sticky headers, scroll indicator, drag and drop actions on items, multiview types items etc. A developer should be able to make an adapter of his need by extending RecyclerView.Adapter. There are many custom adapters developers have shared which comes with built in functionalities. FastAdapter is one of them which comes with all the good functionalities built in and also it is very easy to use. I just got to use this in the Open Event Organizer Android App of which the core feature is Attendees Check In. We have used FastAdapter library to show attendees list which needs many features which are absent in plane RecyclerView.Adapter. FastAdapter is built in such way that there are many different ways of using it on developer's need. I have found a simplest way which I will be sharing here. The first part is extending the item model to inherit AbstractItem. public class Attendee extends AbstractItem<Attendee, AttendeeViewHolder> {   @PrimaryKey   private long id;   ...   ...   @Override   public long getIdentifier() {       return id;   }   @Override   public int getType() {       return 0;   }   @Override   public int getLayoutRes() {       return R.layout.attendee_layout;   }   @Override   public AttendeeViewHolder getViewHolder(View view) {       return new AttendeeViewHolder(DataBindingUtil.bind(view));   }   @Override   public void bindView(AttendeeViewHolder holder, List<Object> list) {       super.bindView(holder, list);       holder.bindAttendee(this);   }   @Override   public void unbindView(AttendeeViewHolder holder) {       super.unbindView(holder);       holder.unbindAttendee();   } } The methods are pretty obvious by name. Implement these methods accordingly. You may notice that we have used Databinding here to bind data to views but it is not necessary. Also you will have to create your ViewHolder for adapter. You can either use RecyclerView.ViewHolder or you can just create a custom one by inheriting it as per your need. Once this part is over you are half done as most of the things are been taken care in model itself. Now we will be writing code for adapter and setting it to your RecyclerView. FastItemAdapter<Attendee> fastItemAdapter = new FastItemAdapter<>(); fastItemAdapter.setHasStableIds(true); ... // functionalities related code ... recyclerView.setAdapter(fastItemAdapter); Initialize FastItemAdapter which will be our main adapter handling all the direct functions related to the RecyclerView. Set up some boolean constants according to the project need. In our project we have Attendee model which has id as a primary field. FastItemAdapter can take advantage of distinct field of the model called as identifier . Hence it is set true as Attendee model has id field. But you should be careful about setting it to True as then you must have implemented getIdentifier in the model to return correct field which will be used as an identifier by our adapter. And the adapter is good to set to the RecyclerView. Now we got to decide…

Continue ReadingUsing FastAdapter in Open Event Organizer Android Project