a generic adapter for recycler view
Only add maven url to your project-level build.gradle
maven { url "https://jitpack.io" }
And then add gradle url to your app-level build.gradle
implementation "com.github.MH480:MHGenericAdapter:0.1.5"
* You can get rid of creating so many adapter classes for each recycler view
* you can code less and use more
* you can have onClick and onLongClick functionalities
* you will be able to have selectable items
* Empty view is added,so you can have recycler view with empty view
* simply bind your layout and data using @MHBindView annotation
* simply make a view clickable using @MHBindView annotation
After your build finished, you can use library as showen below
you can use it like simple adapter but you must pass 3 steps
first define the items model as seperate java class
here is my ItemModel
class
public class ItemModel
{
public int id;
public String title;
}
second create the viewholder class as seperate java class as below
the ViewHolderModel
@MHBindView(R.layout.item) // defines the layout id
public class ViewHolderModel
{
@MHBindView(value = R.id.tvID) // defines the id of the view
public TextView tID;
@MHBindView(value = R.id.btnTitle,isClickable = true) //defines the id of the view and adds click listener to it
public Button bTitle;
}
third step is the item.xml file
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tvID"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:id="@+id/btnTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
the ItemModel
class is my items class for adapter items
and the ViewHolderModel
class is my view holder class
and you must pass ViewHolderModel.class as constructor parameter
finaly you can create new instace of #MHGenericAdapter like below
MHRecyclerAdapter<ItemModel,ViewHolderModel> mAdapter;
mAdapter = new MHRecyclerAdapter<ItemModel,ViewHolderModel>(ViewHolderModel.class);
RecyclerView mRecycler = findViewById(R.id.mRecycler);
mRecycler.setAdapter(mAdapter);
mRecycler.addOnItemTouchListener(mAdapter.buildTouchItemListener(this, mRecycler, this));
We are still working
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
- Mohammad Hoseini - Initial work - sanwix
See also the list of contributors who participated in this project.
This project is licensed under the Apache.2 License - see the LICENSE.md file for details
- Hat tip to anyone who's code was used
- Inspiration
- etc