A Fast Scroller for the RecyclerView world!

Overview

RecyclerViewFastScroller

The RecyclerViewFastScroller is a widget that can be added to a layout and connected to a RecyclerView for fast scrolling.

This project is a demonstration of using the RecyclerViewFastScroller widget in a simple activity that uses the basic workings of com.example.android.recyclerview from the v21 Android samples.

RecyclerViewFastScroller screenshot RecyclerViewFastScroller with section indicator screenshot

As of b3e2d2f, there is now support for adding a SectionIndicator widget, which connects to the scroller. This adds functionality similar to Google's Lollipop Contacts application.

Download

You can grab the current version of the library from maven central

compile 'xyz.danoz:recyclerviewfastscroller:0.1.3'

Usage

Below are some simple steps to using a RecyclerViewFastScroller. Currently, there is only a single implementation (VerticalRecyclerViewFastScroller), so that will be used here.

The best way to check everything out is to peruse the example code and run the sample Application. See how VerticalRecyclerViewFastScroller is utilized in the recycler_view_frag.xml.

Example Code
  1. In the activity or fragment XML where your RecyclerView resides, include a VerticalRecyclerViewFastScroller object. The following example would be in a relative layout:
...
  <android.support.v7.widget.RecyclerView
      android:id="@+id/recyclerView"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      />

  <xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
      android:id="@+id/fast_scroller"
      android:layout_width="@dimen/however_wide_you_want_this"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      />
...
  1. In your fragment or activity where you setup layout programmatically, simply hook up the fast scroller to the recycler as follows:
...
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false);
      ...
      
      // Grab your RecyclerView and the RecyclerViewFastScroller from the layout
      RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView);
      VerticalRecyclerViewFastScroller fastScroller = (VerticalRecyclerViewFastScroller) rootView.findViewById(R.id.fast_scroller);
      
      // Connect the recycler to the scroller (to let the scroller scroll the list)
      fastScroller.setRecyclerView(recyclerView);
      
      // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
      recyclerView.setOnScrollListener(fastScroller.getOnScrollListener());
      
      ...
      return rootView;
  }
...
Optional usage

There are currently a few attributes that can be used to customize the vertical fast scroller:

  <attr name="rfs_barColor" format="color|reference" />
  <attr name="rfs_barBackground" format="reference" />
  <attr name="rfs_handleColor" format="color|reference" />
  <attr name="rfs_handleBackground" format="reference" />

You can see usage of some of these in the example recycler_view_with_fast_scroller_fragment.xml which is the layout for the example app's single fragment.

SectionIndicators

Refer to RecyclerViewWithSectionIndicatorFragment and the corresponding recycler_view_with_fast_scroller_section_title_indicator_fragment.xml in order to find an implementation that adds the Lollipop-Contacts-like section indicator. In addition to the above, you will need to include the indicator in your layout (example here from recycler_view_with_fast_scroller_section_title_indicator_fragment.xml):

...
    <xyz.danoz.recyclerviewfastscroller.sample.ui.example.ColorGroupSectionTitleIndicator
      android:id="@+id/fast_scroller_section_title_indicator"
      android:layout_width="wrap_content"
      android:layout_height="@dimen/list_item_height"
      android:layout_toLeftOf="@id/fast_scroller"
      android:layout_toStartOf="@id/fast_scroller"

      recyclerviewfastscroller:rfs_backgroundColor="@android:color/white"
      recyclerviewfastscroller:rfs_textColor="@android:color/black"
       />
...

and then connect it to the scroller in the fragment:

...
    // Connect the section indicator to the scroller
    fastScroller.setSectionIndicator(sectionTitleIndicator);
...

Contribution

Feel free to submit pull requests and create issues! I will try to be vigilant about maintaining this library, but may not always be as fast as you would like ;)

Comments
  • import error: Error:No such property: OSSRH_USERNAME for class: ...

    import error: Error:No such property: OSSRH_USERNAME for class: ...

    I keep getting this error when trying to import the project into Android-Studio:

    Error:No such property: OSSRH_USERNAME for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer

    What is this? How can I fix this?

    opened by AndroidDeveloperLB 14
  • NullPointerException with null data in adapter

    NullPointerException with null data in adapter

    My data in my adapter is empty when the view is loaded and I get the following exception.

    java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference at android.support.v7.widget.RecyclerView.getChildViewHolder(RecyclerView.java:2567) at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress(VerticalLinearLayoutManagerScrollProgressCalculator.java:29) at xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller.onLayout(AbsRecyclerViewFastScroller.java:202) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966)

    The problem is in VerticalLinearLayoutManagerScrollProgressCalculator:

    @Override
    public float calculateScrollProgress(RecyclerView recyclerView) {
        LinearLayoutManager layoutManager = (LinearLayoutManager) recyclerView.getLayoutManager();
        int lastFullyVisiblePosition = layoutManager.findLastCompletelyVisibleItemPosition();
    
        View visibleChild = recyclerView.getChildAt(0);
        ViewHolder holder = recyclerView.getChildViewHolder(visibleChild);
    

    There is no child at index 0.

    This method should handle the case when the RecyclerView has no children, such as when there is not yet any data.

    opened by timothyjc 8
  • NullPointerException right when starting the sample

    NullPointerException right when starting the sample

    I keep getting this exception:

    java.lang.NullPointerException: Attempt to invoke interface method 'float xyz.danoz.recyclerviewfastscroller.calculation.progress.TouchableScrollProgressCalculator.calculateScrollProgress(android.support.v7.widget.RecyclerView)' on a null object reference
        at xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller$1.onScrolled(AbsRecyclerViewFastScroller.java:185)
        at android.support.v7.widget.RecyclerView.notifyOnScrolled(RecyclerView.java:3248)
        at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2229)
    

    I've used Eclipse since for some reason I can't import the project using Android-Studio (wrote about it here: https://github.com/danoz73/RecyclerViewFastScroller/issues/19 ) .

    bug 
    opened by AndroidDeveloperLB 5
  • [Request] Package as library module and present on Android Arsenal

    [Request] Package as library module and present on Android Arsenal

    First, I think this library is superb, because many Android developers desire fast scrolling feature for RecyclerView. However, it's not handy to use this library from other app project, and still a bit buggy for now...

    I suggest that package this library as a library module and present on the Android Arsenal site as soon as possible. If this library becomes more famous, hopefully developers will contribute :smile:

    opened by h6ah4i 4
  • Character is not shows in bubble

    Character is not shows in bubble

    I have used code as follow, but I don't able to see the character in bubble.

    In JavaFile:

    RecyclerView recyclerView = (RecyclerView) findViewById(R.id.rvAddColorMarkUserLists); VerticalRecyclerViewFastScroller fastScroller =(VerticalRecyclerViewFastScroller) findViewById(R.id.fast_scroller); SectionTitleIndicator sectionTitleIndicator =(SectionTitleIndicator) findViewById(R.id.fast_scroller_section_title_indicator); fastScroller.setRecyclerView(recyclerView);

    recyclerView.setAdapter(usersAdapter); recyclerView.setItemAnimator(new DefaultItemAnimator()); // Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)

    // Connect the section indicator to the scroller fastScroller.setSectionIndicator(sectionTitleIndicator); recyclerView.setOnScrollListener(fastScroller.getOnScrollListener()); setRecyclerViewLayoutManager(recyclerView);

    In xml file

    <android.support.v7.widget.RecyclerView android:id="@+id/rvAddColorMarkUserLists" style="@style/recyclerViewListView" android:visibility="visible" android:paddingTop="10dp" />

        <xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
            android:id="@+id/fast_scroller"
            android:layout_width="24dp"
            android:layout_height="match_parent"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:paddingRight="@dimen/margin_small"
            android:paddingEnd="@dimen/margin_small"
            recyclerviewfastscroller:rfs_barColor="@color/white"
            recyclerviewfastscroller:rfs_handleBackground="@drawable/fast_scroller_handle_rounded"
            />
        <xyz.danoz.recyclerviewfastscroller.sectionindicator.ui.ColorGroupSectionTitleIndicator
            android:id="@+id/fast_scroller_section_title_indicator"
            android:layout_width="wrap_content"
            android:layout_height="@dimen/list_item_height"
            android:layout_toLeftOf="@id/fast_scroller"
            android:layout_toStartOf="@id/fast_scroller"
            recyclerviewfastscroller:rfs_backgroundColor="@color/red"
            recyclerviewfastscroller:rfs_textColor="@android:color/white"
            />
    
    opened by naitikvithlani 3
  • Make it work with CoordinatorLayout

    Make it work with CoordinatorLayout

    Hi ...

    Well, I'm not sure if it's an issue or my error, but I want to use CoordinatorLayout in my layout, and when using the FastScroller, it appears in the left side, instead of the right side.

    <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="jahirfiquitiva.iconshowcase.activities.SearchActivity">
    
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:elevation="@dimen/toolbar_elevation"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
        </android.support.design.widget.AppBarLayout>
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/searchGrid"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clipToPadding="false"
            android:fitsSystemWindows="true"
            android:scrollbars="none"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />
    
    <xyz.danoz.recyclerviewfastscroller.vertical.VerticalRecyclerViewFastScroller
          android:id="@+id/fast_scroller"
          android:layout_width="16dp"
          android:layout_height="match_parent"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true"
          />
    
    </android.support.design.widget.CoordinatorLayout>
    

    And 2 things that I would like you to help me fix and/or for you to improve the lib.

    1. RecyclerView.setOnScrollListener is deprecated.... what could be used now?
    2. Make the FastScroller hide if the items are few.

    Thank you.

    opened by jahirfiquitiva 3
  • Cannot load dependency

    Cannot load dependency

    Getting an error when adding compile 'xyz.danoz:recyclerviewfastscroller:0.1.3' into dependency section of build.gradle.

    Error:A problem occurred configuring project ':app'. Could not resolve all dependencies for configuration ':app:_debugCompile'. Could not find com.android.support:recyclerview-v7:22.1.0. Required by: XXX:app:unspecified XXX:app:unspecified > xyz.danoz:recyclerviewfastscroller:0.1.3 Could not find com.android.support:support-v4:22.1.0. Required by: XXX:app:unspecified > xyz.danoz:recyclerviewfastscroller:0.1.3

    opened by sirvar 3
  • New crash new SDK an issue maybe?

    New crash new SDK an issue maybe?

    I updated to the latest recyclerview and sdk and started getting the error below, but downloaded the code and seem to be getting the same error from the sample, not sure what the cause is except that there seems to be an issue with a scroll event being initiated before the "calculator" is created by the onLayout(), I made a hack to fix it by checking if it had been created before calling it and everything works fine.

    03-15 21:12:59.157 3304-3304/xyz.danoz.recyclerviewfastscroller.sample E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: xyz.danoz.recyclerviewfastscroller.sample, PID: 3304 java.lang.NullPointerException: Attempt to invoke interface method 'float xyz.danoz.recyclerviewfastscroller.calculation.progress.TouchableScrollProgressCalculator.calculateScrollProgress(android.support.v7.widget.RecyclerView)' on a null object reference at xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller$1.onScrolled(AbsRecyclerViewFastScroller.java:185) at android.support.v7.widget.RecyclerView.notifyOnScrolled(RecyclerView.java:3248) at android.support.v7.widget.RecyclerView.dispatchLayout(RecyclerView.java:2229) at android.support.v7.widget.RecyclerView.onLayout(RecyclerView.java:2415) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966)

    opened by KennyGoers 2
  • Made declared Styles not clashing with other libraries

    Made declared Styles not clashing with other libraries

    I have the Problem that when i try to implement This into my Current Project, some other library already declares the backgroundColor and textColor attribute.

    For further details on this see: https://code.google.com/p/android/issues/detail?id=22576

    In Short: this is more implementation Friendly to other libs.

    opened by CaptnBlubber 1
  • Cannot display the

    Cannot display the "fastscroll", app is crashing

    I'm trying to implements the FastScroller component but it didn't work because of a NullPointerException, below the stackStrace :

    java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.ViewParent android.view.View.getParent()' on a null object reference at android.support.v7.widget.RecyclerView.getChildViewHolder(RecyclerView.java:2567) at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress(VerticalLinearLayoutManagerScrollProgressCalculator.java:29) at xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller.onLayout(AbsRecyclerViewFastScroller.java:202) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1076) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1703) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1557) at android.widget.LinearLayout.onLayout(LinearLayout.java:1466) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:15596) at android.view.ViewGroup.layout(ViewGroup.java:4966) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2072) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1829) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767) at android.view.Choreographer.doCallbacks(Choreographer.java:580) at android.view.Choreographer.doFrame(Choreographer.java:550) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

    Any solution ?

    opened by ivory972 1
  • Add FastScrollListener, hide handle until scrolled

    Add FastScrollListener, hide handle until scrolled

    Addresses #33 and changes the UX to be more like AOSP. The handle will now be hidden by default until the user scrolls the view, and it will fade in and out at appropriate times. Because the view isn't set to GONE, the user can still use the invisible scroll track to jump straight to a section of the list - lemme know if I should fix that by making the view GONE until the user scrolls.

    opened by firekesti 0
  • com.example.icallerscreenj, PID: 29583     java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.recyclerview.widget.RecyclerView$LayoutManager androidx.recyclerview.widget.RecyclerView.getLayoutManager()' on a null object reference         at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress

    com.example.icallerscreenj, PID: 29583 java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.recyclerview.widget.RecyclerView$LayoutManager androidx.recyclerview.widget.RecyclerView.getLayoutManager()' on a null object reference at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress

    com.example.icallerscreenj, PID: 29583 java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.recyclerview.widget.RecyclerView$LayoutManager androidx.recyclerview.widget.RecyclerView.getLayoutManager()' on a null object reference at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress

    i have issue with this

    opened by masif040 0
  • Crash on recycleview

    Crash on recycleview

    when i using same xml in another Activity i m using 'xyz.danoz:recyclerviewfastscroller:0.1.3'

    java.lang.NullPointerException: Attempt to invoke virtual method 'androidx.recyclerview.widget.RecyclerView$LayoutManager androidx.recyclerview.widget.RecyclerView.getLayoutManager()' on a null object reference at xyz.danoz.recyclerviewfastscroller.calculation.progress.VerticalLinearLayoutManagerScrollProgressCalculator.calculateScrollProgress(VerticalLinearLayoutManagerScrollProgressCalculator.java:25) at xyz.danoz.recyclerviewfastscroller.AbsRecyclerViewFastScroller.onLayout(AbsRecyclerViewFastScroller.java:206)

    opened by SaurabhGaddelpalliwar 2
  • Help with usage

    Help with usage

    Hi thanks for this wonderful library. please can you help with how i can use it for my recyclerview.

    this is my model: public class Country { private int id; private String name, iso2name, iso3name, iso2continent, phone_code, currency, active, added, updated;

    public Country() {
    }
    
    public Country(int id, String name, String iso2name, String iso3name, String iso2continent, String phone_code, String currency, String active, String added, String updated) {
        this.id = id;
        this.name = name;
        this.iso2name = iso2name;
        this.iso3name = iso3name;
        this.iso2continent = iso2continent;
        this.phone_code = phone_code;
        this.currency = currency;
        this.active = active;
        this.added = added;
        this.updated = updated;
    }
    
    public Country(int id, String name, String iso2name, String iso3name, String iso2continent, String phone_code, String currency) {
        this.id = id;
        this.name = name;
        this.iso2name = iso2name;
        this.iso3name = iso3name;
        this.iso2continent = iso2continent;
        this.phone_code = phone_code;
        this.currency = currency;
    }
    
    public Country(int id, String name, String iso2name, String iso3name, String iso2continent, String phone_code, String currency, String active) {
        this.id = id;
        this.name = name;
        this.iso2name = iso2name;
        this.iso3name = iso3name;
        this.iso2continent = iso2continent;
        this.phone_code = phone_code;
        this.currency = currency;
        this.active = active;
    }
    
    public Country(String name, String iso2name, String iso3name, String iso2continent, String phone_code, String currency, String active, String added, String updated) {
        this.name = name;
        this.iso2name = iso2name;
        this.iso3name = iso3name;
        this.iso2continent = iso2continent;
        this.phone_code = phone_code;
        this.currency = currency;
        this.active = active;
        this.added = added;
        this.updated = updated;
    }
    
    public int getId() {
        return id;
    }
    
    public void setId(int id) {
        this.id = id;
    }
    
    public String getName() {
        return name;
    }
    
    public void setName(String name) {
        this.name = name;
    }
    
    public String getIso2name() {
        return iso2name;
    }
    
    public void setIso2name(String iso2name) {
        this.iso2name = iso2name;
    }
    
    public String getIso3name() {
        return iso3name;
    }
    
    public void setIso3name(String iso3name) {
        this.iso3name = iso3name;
    }
    
    public String getIso2continent() {
        return iso2continent;
    }
    
    public void setIso2continent(String iso2continent) {
        this.iso2continent = iso2continent;
    }
    
    public String getPhone_code() {
        return phone_code;
    }
    
    public void setPhone_code(String phone_code) {
        this.phone_code = phone_code;
    }
    
    public String getCurrency() {
        return currency;
    }
    
    public void setCurrency(String currency) {
        this.currency = currency;
    }
    
    public String getActive() {
        return active;
    }
    
    public void setActive(String active) {
        this.active = active;
    }
    
    public String getAdded() {
        return added;
    }
    
    public void setAdded(String added) {
        this.added = added;
    }
    
    public String getUpdated() {
        return updated;
    }
    
    public void setUpdated(String updated) {
        this.updated = updated;
    }
    
    @Override
    public String toString() {
        return "Country{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", iso2name='" + iso2name + '\'' +
                ", iso3name='" + iso3name + '\'' +
                ", iso2continent='" + iso2continent + '\'' +
                ", phone_code='" + phone_code + '\'' +
                ", currency='" + currency + '\'' +
                ", active='" + active + '\'' +
                ", added='" + added + '\'' +
                ", updated='" + updated + '\'' +
                '}';
    }
    

    }

    and this is my adapter public class CountryAdapter extends RecyclerView.Adapter<CountryAdapter.ViewHolder> implements Filterable {

    public List<Country> countries, countryFiltered;
    public Context context;
    public AdapterListener adapterListener;
    public CountryFilter countryFilter;
    private ColorGenerator colorGenerator = ColorGenerator.MATERIAL;
    
    public CountryAdapter(List<Country> countries, Context context, AdapterListener adapterListener) {
        this.context = context;
        this.countries = countries;
        this.countryFiltered = countries;
        this.adapterListener = adapterListener;
    }
    
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
        View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.country_item, viewGroup, false);
        return new ViewHolder(v);
    }
    
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        TextDrawable drawable = TextDrawable.builder()
                .beginConfig()
                .textColor(Color.BLACK)
                .useFont(Typeface.DEFAULT)
                .fontSize(80)
                .bold()
                .toUpperCase()
                .endConfig()
                .buildRound(countries.get(position).getName().substring(0, 1), colorGenerator.getColor(countries.get(position).getName()));
        viewHolder.getImageView().setImageDrawable(drawable);
        viewHolder.getTvName().setText(countries.get(position).getName());
        viewHolder.getTvCode().setText(countries.get(position).getPhone_code());
    }
    
    @Override
    public int getItemCount() {
        return countries.size();
    }
    
    @Override
    public Filter getFilter() {
        if (countryFilter == null) {
            countryFilter = new CountryFilter(countryFiltered, this);
        }
        return countryFilter;
    }
    
    public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
    
        AppCompatImageView imageView;
        AppCompatTextView tvName, tvCode;
    
        ViewHolder(View itemView) {
            super(itemView);
            tvName = itemView.findViewById(R.id.tvName);
            tvCode = itemView.findViewById(R.id.tvCode);
            imageView = itemView.findViewById(R.id.imageView);
            itemView.setOnClickListener(this);
        }
    
        @Override
        public void onClick(View v) {
            adapterListener.onSelected(countries.get(getAdapterPosition()));
        }
    
        private AppCompatImageView getImageView() {
            return imageView;
        }
    
        private AppCompatTextView getTvName() {
            return tvName;
        }
    
        private AppCompatTextView getTvCode() {
            return tvCode;
        }
    }
    

    }

    Thanks again

    opened by iamchurchill 0
Releases(0.1.0)
Owner
Daniel Smith
Daniel Smith
Pumped up RecyclerView

##Description This is an attempt to make RecyclerView easier to use. Features built in: ProgressBar while adapter hasn't been set EmptyView if adapter

Anton Malinskiy 2.6k Jan 5, 2023
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
. Android library that integrate sticky section headers in your RecyclerView

recyclerview-stickyheaders Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. Thes

null 968 Nov 10, 2022
An adapter which could be used to achieve a parallax effect on RecyclerView.

android-parallax-recycleview Integration Step 1. Add the JitPack repository to your build file repositories { maven { url "https://jitpack

Pedro Oliveira 1.6k Nov 17, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 5, 2023
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Yoshihito Ikeda 414 Nov 21, 2022
*** WARNING: This library is no longer maintained *** An easy way to add a simple 'swipe-and-do-something' behavior to your `RecyclerView` items. Just like in Gmail or Inbox apps.

SwipeToAction An easy way to add a simple 'swipe-and-do-something' behavior to your RecyclerView items. Just like in Gmail or Inbox apps. Integration

Victor Calvello 223 Nov 16, 2022
RecyclerView extension library which provides advanced features. (ex. Google's Inbox app like swiping, Play Music app like drag and drop sorting)

Advanced RecyclerView This RecyclerView extension library provides Google's Inbox app like swiping, Play Music app like drag-and-drop sorting and expa

Haruki Hasegawa 5.2k Dec 23, 2022
ItemDecoration for RecyclerView using LinearLayoutManager for Android

RecyclerItemDecoration RecyclerItemDecoration allows you to draw divider between items in recyclerview with multiple ViewType without considering item

magiepooh 328 Dec 27, 2022
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

timehop 3.7k Dec 31, 2022
A horizontal view scroller library for Android

View Flow for Android ViewFlow is an Android UI widget providing a horizontally scrollable ViewGroup with items populated from an Adapter. Scroll down

Patrik Åkerfeldt 1.8k Dec 29, 2022
[] Super fast and easy way to create header for Android RecyclerView

DEPRECATED I created this library back in the day when I thought RecyclerView was all new and difficult. Writing an adapter that could inflate multipl

Bartek Lipinski 1.3k Dec 28, 2022
Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.

Kiel Kiel is a RecyclerView.Adapter with a minimalistic and convenient Kotlin DSL which provides utility on top of Android's normal RecyclerView.Adapt

ibrahim yilmaz 370 Jan 2, 2023
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview Create carousel effect in recyclerview with the CarouselRecyclerview in a simple way. Including in your project Gradle Add below

Jack and phantom 514 Jan 8, 2023
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
ANDROID. ChipsLayoutManager (SpanLayoutManager, FlowLayoutManager). A custom layout manager for RecyclerView which mimicric TextView span behaviour, flow layouts behaviour with support of amazing recyclerView features

ChipsLayoutManager This is ChipsLayoutManager - custom Recycler View's LayoutManager which moves item to the next line when no space left on the curre

Oleg Beloy 3.2k Dec 25, 2022
A RecyclerView that implements pullrefresh and loadingmore featrues.you can use it like a standard RecyclerView

XRecyclerView a RecyclerView that implements pullrefresh , loadingmore and header featrues.you can use it like a standard RecyclerView. you don't need

XRecyclerView 5.3k Dec 26, 2022
Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Carousel Recyclerview let's you create carousel layout with the power of recyclerview by creating custom layout manager.

Jack and phantom 504 Dec 25, 2022