Popularity
0.4
Growing
Activity
0.0
Declining
2
1
2

Description

This is a generic adapter developed for all the recycler views in Android. Using this library eliminates the need of creating a separate adapter for every recycler view. Please checkout the usage of the library and its benefits on the GitHub page.

Programming language: Java
License: MIT License
Tags: Android     SDK     Library     App Dev     App Development     RecyclerView     Java     Kotlin     Android Library    

KRecyclerViewAdapter alternatives and similar libraries

Based on the "SDK" category.
Alternatively, view KRecyclerViewAdapter alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of KRecyclerViewAdapter or a related project?

Add another 'SDK' Library

README

KRecyclerViewAdapter

platform API License: MIT Language: JAVA Twitter

A generic recyclerview adapter for all your recycler views.
No need to create a custom adapter for every recyclerview.

Dependency:

Add the following in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

Add the dependency in your app level gradle:

implementation 'com.github.KalpeshTalkar:KRecyclerViewAdapter:1.0.0'

Usage:

Extend your holder from KRecyclerViewHolder

Refer the sample code below:

public class MyHolder extends KRecyclerViewHolder {

    private TextView titleLabel, descLabel;

    public MyHolder(View itemView) {
        super(itemView);
        titleLabel = (TextView) itemView.findViewById(R.id.titleLabel);
        descLabel = (TextView) itemView.findViewById(R.id.descLabel);
    }

    @Override
    protected void setSelected(@NonNull Context context, boolean selected) {
        super.setSelected(context, selected);
        // This method is called whenever the holder is selected/unselected.
        if (selected) {
            // Selected
        } else {
            // Unselected
        }
    }

    @Override
    protected void setData(@NonNull Context context, @NonNull Object itemObject) {
        super.setData(context, itemObject);
        // This method is called automatically by the adapter.
        // override this method and set your data here...
        // Check the type of itemObject
        if (itemObject instanceof MyObject) {
            MyObject myObject = (MyObject)itemObject;
            titleLabel.setText(myObject.title);
            descLabel.setText(myObject.description);
        }
    }

}

Set your adapter (Single View Type)

KRecyclerViewAdapter adapter = new KRecyclerViewAdapter(this, YOUR_ARRAY, new KRecyclerViewHolderCallBack() {
    @Override
    public KRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent) {
        View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_item, parent, false);
        return new MyHolder(layoutView);
    }

    @Override
    public void onHolderDisplayed(@NonNull KRecyclerViewHolder holder, int position) {
        Log.i("onHolderDisplayed", "Holder Displayed At: " + position);
    }       
}, new KRecyclerViewItemClickListener() {
    @Override
    public void onRecyclerItemClicked(@NonNull KRecyclerViewHolder holder, @NonNull Object itemObject, int itemPosition) {
        Toast.makeText(MainActivity.this, "Clicked position " + itemPosition, Toast.LENGTH_SHORT).show();
    }
});

YOUR_RECYCLER_VIEW.setAdapter(adapter);

Other properties

adapter.allowsSingleSelection = true;           // Enables single selection
adapter.allowsMultipleSelection = true;         // Enables multiple selection
adapter.deselectItemOnClickIfSelected = true;   // Deselects the item if already selected.

adapter.getSelectedIndexes();                   // Get list of selected item positions

Set your adapter (Multiple View Type)

KRecyclerViewAdapter adapter = new KRecyclerViewAdapter(this, YOUR_ARRAY, new KRecyclerViewHolderViewTypeCallBack() {
    @Override
    public int recyclerItemViewType(int position, @NonNull Object itemObject) {
        if (position % 2 == 0) {
            return 1;
        } else {
            return 2;
        }
    }

    @Override
    public KRecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        if (viewType == 1) {
            View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.simple_item, null);
            return new SimpleHolder(layoutView);
        } else {
            View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.another_item, null);
            return new AnotherHolder(layoutView);
        }
    }

    @Override
    public void onHolderDisplayed(@NonNull KRecyclerViewHolder holder, int position) {
        Log.i("onHolderDisplayed", "Holder Displayed At: " + position);
    }
}, new KRecyclerViewItemClickListener() {
    @Override
    public void onRecyclerItemClicked(@NonNull KRecyclerViewHolder holder, @NonNull Object itemObject, int itemPosition) {
        Toast.makeText(MainActivity.this, "Clicked position " + itemPosition, Toast.LENGTH_SHORT).show();
    }
});

YOUR_RECYCLER_VIEW.setAdapter(adapter);


*Note that all licence references and agreements mentioned in the KRecyclerViewAdapter README section above are relevant to that project's source code only.