@@ -23,7 +23,7 @@ The next task is to add the dependecy to your _app_ `build.gradle` file.
2323``` gradle
2424 dependencies {
2525 ...
26- implementation 'com.github.horaciocome1:simple-recyclerview-adapter:0.1.0 '
26+ implementation 'com.github.horaciocome1:simple-recyclerview-adapter:0.1.2 '
2727 }
2828```
2929Now you ready to go. Except that you should _ ** sync your project** _ first.
@@ -33,58 +33,56 @@ As mention on IO18, android support libraries will not be updated anymore, thats
3333I am wondering if it is necessary to do a separate lib for suppor appcompat. Email me if you thinking on that.
3434
3535## How to use
36- Intanciate a class ` SimpleRecyclerViewAdapter ` by using its own builder.
37- ``` java
38- SimpleRecyclerViewAdapter adapter = new SimpleRecyclerViewAdapter .Builder ()
39- .setItemLayout(R . layout. your_item_layout)
40- .setList(yourList)
41- .setOnBindViewHolder(new SimpleRecyclerViewAdapter .OnBindViewHolder () {
42- @Override
43- public void onBind (@NonNull SimpleRecyclerViewAdapter .ViewHolder holder , Object object ) {
44- // bind object data to the view
45- }
46- })
47- .build();
48- recyclerView. setAdapter(adapter);
36+ Call the default constructor passing as Datatype the class of your list objects.
37+ ``` kotlin
38+ recyclerView.adapter = SimpleRecyclerViewAdapter <DataType >().apply {
39+ itemLayout = R .layout.your_item_layout
40+ list = yourList
41+ setOnBindViewHolder { holder, dataType -> /* bind data here */ }
42+ }
4943```
5044### Examples
5145Lets have a look at some common binding examples
52- ``` java
53- @Override
54- public void onBind(@NonNull SimpleRecyclerViewAdapter . ViewHolder holder, Object object) {
55- // binding a string to a textview
56- ((TextView ) holder. getViewById(R . id. your_item_layout_textview_id)). setText((String ) object)
57-
58- // binding and image to an imageview using Picasso or Glide
59- Picasso . with(context)
60- .load(((Person ) object). getProfilePic())
61- .into((ImageView ) holder. getViewById(R . id. your_item_layout_imageview_id))
46+ ``` kotlin
47+ recyclerView.adapter = SimpleRecyclerViewAdapter <User >().apply {
48+ itemLayout = R .layout.item_user
49+ list = users
50+ setOnBindViewHolder { holder, user ->
51+ holder.findViewById<Textview >(R .id.name).text = user.name
52+ holder.findViewById<Textview >(R .id.age).text = user.age
53+ ImageLoader .with (context)
54+ .load(user.photo)
55+ .into(holder.findViewById<ImageView >(R .id.photo))
56+ }
6257}
6358```
6459
65- ### Kotlin
66- ``` kotlin
67- val adapter = SimpleRecyclerViewAdapter .Builder ()
68- .setList(posts())
69- .setItemLayout(R .layout.item_post)
70- .setOnBindViewHolder { holder, `object ` -> // bind your data here }
71- .build()
72- recyclerView.adapter = adapter
60+ ### Java
61+ ``` java
62+ SimpleRecyclerViewAdapter<DataType > adapter = new SimpleRecyclerViewAdapter<> ();
63+ adapter. setItemLayout(R . layout. your_item_layot);
64+ adapter. setList(yourList);
65+ adapter. setOnBindViewHolder(new Function2<SimpleRecyclerViewAdapter . ViewHolder , String , Unit >() {
66+ @Override
67+ public Unit invoke (SimpleRecyclerViewAdapter .ViewHolder viewHolder , DataType data ) {
68+ // bind data here
69+ }
70+ });
71+ recyclerView. setAdapter(adapter);
7372```
7473
7574As you can see, casting is mandatory. Remember that this is a general porpose Adapter, althougth it is returning your own object, the class itself dont know it.
7675
7776### Troubleshooting
78- Notice that it is crucial to call `build( .. . )` so that the listener could be initialized .
79- It makes no sense only calling `build( .. . )` .
77+ Naturally the adapter needs an item_layout, an list and an onBindViewHolder() implementation to display the list on screen .
78+ None of this is optional, so not setting them may lead to runtime app crash .
8079``` kotlin
81- val adapter = SimpleRecyclerViewAdapter . Builder ().build()
82- recyclerView.adapter = adapter
80+ // this is what you need to a void
81+ recyclerView.adapter = SimpleRecyclerViewAdapter < DataType >()
8382```
84- This might lead to app crash.
8583
8684### "Build or sinchronization failed!"
87- Please reference to the part on the start where i talked about support libraries.
85+ This is might be a dependency matter. Please reference to the part on the start where i talked about support libraries.
8886
8987## Licenses
9088 Copyright 2018 Horácio Flávio Comé Júnior
@@ -106,6 +104,6 @@ I am open to suggestions of any kind.
106104Please be expressive, so others so we'all will be able to understand each other!
107105Report any issues, please!
108106
109- # Simple RecyclerView Utils
107+ ## Simple RecyclerView Utils
110108This is part of a serie of libraries that pretend to make recyclerview usage more easy.
111109For a touch listener please see [ Simple RecyclerView Touch Listener] ( https://github.com/horaciocome1/simple-recyclerview-touch-listener )
0 commit comments