B4A Library [Lib, Chargeable] Amir_RecyclerView

New b4a library! :)

RecyclerView, an important part of the sdk and android for making a custom list with better Layout , animation , and fixed for large data set.


Amir_RecyclerView released new version that we call it AX_RecyclerView.

version 1.0.8 is last update for Amir_RecyclerView and we will work on AX_RecyclerView only in future.


RecyclerView Android X : https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView

"RecyclerView is part of the v7 support library which means you can use it on anything that has api 7 and up"

543434345345.jpg



Advantages of using recyclerview instead listview:
  • ViewHolder Pattern
In a ListView, it was recommended to use the ViewHolder pattern but it was never a compulsion. In case of RecyclerView, this is mandatory using the RecyclerView.ViewHolder class. This is one of the major differences between the ListView and the RecyclerView.​

  • LayoutManager
This is another massive enhancement brought to the RecyclerView. In a ListView, the only type of view available is the vertical ListView. There is no official way to even implement a horizontal ListView.​
Now using a RecyclerView, we can have a:​
i) LinearLayoutManager - which supports both vertical and horizontal lists,​
ii) StaggeredLayoutManager - which supports Pinterest like staggered lists,​
iii) GridLayoutManager - which supports displaying grids as seen in Gallery apps.​
And the best thing is that we can do all these dynamically as we want.​

  • Item Animator
ListViews are lacking in support of good animations, but the RecyclerView brings a whole new dimension to it. Using the RecyclerView.ItemAnimator class, animating the views becomes so much easy and intuitive.​

  • Item Decoration
In case of ListViews, dynamically decorating items like adding borders or dividers was never easy. But in case of RecyclerView, the RecyclerView.ItemDecorator class gives huge control to the developers but makes things a bit more time consuming and complex.​

  • OnItemTouchListener
Intercepting item clicks on a ListView was simple, thanks to its AdapterView.OnItemClickListener interface. But the RecyclerView gives much more power and control to its developers by the RecyclerView. OnItemTouchListener but it complicates things a bit for the developer.​


For more info:
https://developer.android.com/reference/android/support/v7/widget/RecyclerView

You can add plugins as library and connect it to Amir_RecyclerView using a line of code

Current Plugins :
  • Amir_RVHeaderFooter
  • Amir_RVToolbarParallax
  • Amir_RVEmptyView
  • Amir_RVCardSlider
  • Amir_RVCarousel
  • Amir_RVDiscrete
  • Amir_RVExpandable
  • Amir_RVFanLayout
  • Amir_RVFeature
  • Amir_RVItemPicker ( deprecated )
  • Amir_RVLayoutAnimation
  • Amir_RVMultiSelection
  • Amir_RVParallax
  • Amir_RVRefreshLayout
  • Amir_RVShimmer
  • Amir_RVSkidRight
  • Amir_RVSwipeCards
  • Amir_RVVegaLayout
  • Amir_RVEchelon
  • Amir_WearableRecyclerView
  • Amir_RVDragItem
  • Amir_RVStickyHeader
  • AX_RecyclerViewPager ( deprecated )
  • Amir_RVAnimators
  • AX_RVSelection
  • AX_RVItemPicker
  • AX_RVPageIndicator
  • Amir_RVChipsLayoutManager
  • AX_RVSwipeLayout 1.00
  • AX_RVHeaderParallax
  • Amir_RVCardViewAdapter
  • Amir_RVExpandableStickyHeader
  • Amir_RVOverScroll
  • AX_RVFastScroller
  • AX_RVHeightStaggeredGrid
  • Amir_RVDragAndSwipe ( NEW )

Demo and samples how to use :

Download the DEMO.apk ( updated in 28th of July 2019 )
Download Demo Source Code

Extra Samples are here


Current version of Amir_RecyclerView : 1.2.0

Be sure to check the apk sample before purchasing.


You can have this fantastic library just with $25 ( only Amir_RecyclerView )
Full packages include all plugins only $35

Short documentations attached , special thanks to fredo

After your purchase please send me an email with your purchase detail ( alimanam@gmail.com )

 

Attachments

  • Amir_RecyclerView_FullPackage_1.0.2.LIBDOC.zip
    61.1 KB · Views: 908
Last edited:

alimanam3386

Active Member
Licensed User
Hi

how can I get item / text

Private Sub Amir_onItemClick (Parent As Panel,Position As Int)

Several samples are available in the full package you can see
you have the position of item also you have the parent of item so it is super easy to get everything.
 

alimanam3386

Active Member
Licensed User
AX_RecyclerView Version 1.2.0 released
  • AX_RVSimpleAdapter (Class)
  • Amir_RVDragAndSwipe (Plugin)
  • AutoCycle

RVDragItem + RVSwipeItem = RVDragAndSwipe

You can StartDrag with View clicks and disable default long press drag.
Based on this plugin RVDragItem and RVSwipeItem are deprecated

Also try ReplyWithSwipe Sample:

1.png



AX_RecyclerViewPager has been deleted!

You can use this line to create a ViewPager Layout :

B4X:
RV.Initializer("EventName).ViewPager.Build


AX_RVSimpleAdapter (New Class)
Create a simple rvadapter just like default b4a ListView adapter!
Example :

B4X:
Dim Adapter As AX_RVSimpleAdapter
Adapter.Initialize("EventName")
Adapter.SingleLineLayout.Label.TextColor = Colors.Red
...
...
Adapter.AddSingleLine("SingleLine")
Adapter.AddTwoLines("Line1","Line2")
Adapter.AddTwoLinesAndBitmap("Line1","Line2",Bitmap)
Adapter.AddCustomItem(ViewType,Tag,Height)
RV.Adapter = Adapter

and also you have onCreateLayout and onBindLayout Events to set your custom options

2.jpg



AutoCycle :
Auto Scroller for RecyclerView.
also you can set CycleDirection.

B4X:
RV.AutoCycle.Initialize
RV.AutoCycle.CycleDirection = RV.AutoCycle.AUTO_CYCLE_DIRECTION_RIGHT
RV.AutoCycle.ScrollTimeInMillis = 3000
RV.AutoCycle.StartAutoCycle

ForceRTL :
B4X:
RV.Initializer("EV).ListView.ForceRTL(True).Build

New Scroll Methods :
B4X:
RV.SmoothScrollToPosition3(Position,SpeedFactory)
RV.ScrollToPositionWithOffset(Position,Offset)
 
Last edited:

itgirl

Active Member
Licensed User
I think there is a bug in the new version when i set _onItemTouch event and try to scroll a horizontal i get
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
 

alimanam3386

Active Member
Licensed User
I think there is a bug in the new version when i set _onItemTouch event and try to scroll a horizontal i get
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean

tye to modify the event :
B4X:
Sub RV_onItemTouch (Parent As Panel,Position As Int,Action As Int,X As Float,Y As Float) As Boolean
Return false
End Sub
 

itgirl

Active Member
Licensed User
tye to modify the event :
B4X:
Sub RV_onItemTouch (Parent As Panel,Position As Int,Action As Int,X As Float,Y As Float) As Boolean
Return false
End Sub
Yeah thats exactly what i did in order to solve this problem and it works, but i thought i should mention it so for the next version it will be automatically added :) thank you so much for the great work ;)
 

skaliwag

Member
Licensed User
There seems to be a problem with the size of the Panel passed to _onCreateViewHolder and onBindViewHolder as the Parent

Version 1.10 passes the actual Width e.g. 720
Version 1.20 passes -1 as the Width
 

alimanam3386

Active Member
Licensed User
There seems to be a problem with the size of the Panel passed to _onCreateViewHolder and onBindViewHolder as the Parent

Version 1.10 passes the actual Width e.g. 720
Version 1.20 passes -1 as the Width

-1 means Match Parent
720 = RecyclerView width
Try this :
B4X:
Dim RV As View = Parent.Panel
RV.Width

And if you are using Ripple or CardView plugin , try this one :
B4X:
Dim RV As View = Parent.Panel
RV = RV.Parent
RV.Width
 

skaliwag

Member
Licensed User
-1 means Match Parent
720 = RecyclerView width
Try this :
B4X:
Dim RV As View = Parent.Panel
RV.Width

And if you are using Ripple or CardView plugin , try this one :
B4X:
Dim RV As View = Parent.Panel
RV = RV.Parent
RV.Width

Thanks, but that does not work.

Using the Basic Sample Amir_Recyclable provided with the library as an example, the Panel passed to Amir_onCreateViewHolder does not have a Parent Panel.
This sample does not work on my system as it uses Parent.Width to calculate the new Panel size, and this is giving a value of -1.
Can someone confirm that this sample works correctly with Version 1.20 ?
Again, there is no problem with Version 1.10
 

itgirl

Active Member
Licensed User
Thanks, but that does not work.

Using the Basic Sample Amir_Recyclable provided with the library as an example, the Panel passed to Amir_onCreateViewHolder does not have a Parent Panel.
This sample does not work on my system as it uses Parent.Width to calculate the new Panel size, and this is giving a value of -1.
Can someone confirm that this sample works correctly with Version 1.20 ?
Again, there is no problem with Version 1.10
yeah you are right i faced the same issue and i had to put in Parent.width=100%x in order for it to work
 

alimanam3386

Active Member
Licensed User
Thanks, but that does not work.

Using the Basic Sample Amir_Recyclable provided with the library as an example, the Panel passed to Amir_onCreateViewHolder does not have a Parent Panel.
This sample does not work on my system as it uses Parent.Width to calculate the new Panel size, and this is giving a value of -1.
Can someone confirm that this sample works correctly with Version 1.20 ?
Again, there is no problem with Version 1.10

I repeat my answer again!

-1 means Match Parent in code

Simply put this line in onCreate
(Only if you are using LinearLayout, GridLayout will calculate width automatically)

B4X:
Parent.Width = 100%x

By the way again, it's better Parent.Width be -1 always , so if you can just change Paren.Width to 100%x OR what you want in your code.
 
Last edited:

Inman

Well-Known Member
Licensed User
I bought the library last year and have not tried it out until now. Do you have a vertical grid view example (with 2 items per row) that is working with v1.20 of the library?
 

alimanam3386

Active Member
Licensed User
I bought the library last year and have not tried it out until now. Do you have a vertical grid view example (with 2 items per row) that is working with v1.20 of the library?

Have look to the sample code please :
B4X:
Sub Globals
    Type item (id As String , title As String)
    Private rv As AX_RecyclerView
    Private adapter As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    rv.Initializer("rv").GridView(2).Vertical.Build
  
    Activity.AddView(rv , 0 , 0 , 100%x ,100%y)
    rv.DefaultAdapter
  
    Dim l As List
    l.Initialize
    adapter.Initialize
    For i = 0 To 101
        Dim item As item
        item.Initialize
        item.id = i
        item.title = "Item#" & i
        adapter.Add(item)
    Next
    rv.Adapter2.NotifyDataSetChanged
End Sub

Private Sub rv_GetItemCount As Int
    Return adapter.Size
End Sub

Private Sub rv_onCreateViewHolder (Parent As Panel,ViewType As Int)
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.RGB(Rnd(0,255) , Rnd(0,255) , Rnd(0,255))
    Parent.AddView(p , 0 , 0 , 50%x , 25%y)
  
    Dim l As Label
    l.Initialize("")
    l.Gravity = Gravity.CENTER
    l.TextColor = Colors.Black
    l.TextSize = 16
    p.AddView(l , 0 , 0 , -1,-1)
  
End Sub

Private Sub rv_onBindViewHolder (Parent As Panel,Position As Int)
    Dim item = adapter.Get(Position) As item
  
    Dim p As Panel = Parent.GetView(0)
    Dim l As Label = P.GetView(0)
  
    l.Text = item.title
  
    Parent.Height = 25%y
  
End Sub
 

Attachments

  • sample.zip
    8.3 KB · Views: 90
  • 3462423.jpg
    3462423.jpg
    12.7 KB · Views: 114
Last edited:

Inman

Well-Known Member
Licensed User
Thank you. Works great. Some more doubts.

Based on the example, my understanding is that you need to define your layout (add panels, labels, imageviews etc) in onCreateViewHolder and then set its values in onBindViewHolder. Am I right?

I was looking for a library like Picasso that will load an image from web into an ImageView in a Recycle View grid. In one of your examples, I see the library Amir_Glide being used in a similar way. Does it work like Picasso? As in when it loads an image for the first time, it will cache it and then the next time it will look in cache first before downloading from web again?

Say I want to refresh the grid. As in delete the current items and load a fresh set of images and labels (same layout, different values). What all should I do?
 

alimanam3386

Active Member
Licensed User
Thank you. Works great. Some more doubts.

Based on the example, my understanding is that you need to define your layout (add panels, labels, imageviews etc) in onCreateViewHolder and then set its values in onBindViewHolder. Am I right?
Yes.

I was looking for a library like Picasso that will load an image from web into an ImageView in a Recycle View grid. In one of your examples, I see the library Amir_Glide being used in a similar way. Does it work like Picasso? As in when it loads an image for the first time, it will cache it and then the next time it will look in cache first before downloading from web again?
I did not work with this library but it should be same , the Amir_Glide library uses cache so it just download images JUST once.

Say I want to refresh the grid. As in delete the current items and load a fresh set of images and labels (same layout, different values). What all should I do?

Have look to new sample code for remove or update an item in the grid:
for more support please start new thread.

B4X:
Sub Globals
    Type item (id As String , title As String)
    Private rv As AX_RecyclerView
    Private adapter As dcKeyValueList ' DataCollection Library
End Sub

Sub Activity_Create(FirstTime As Boolean)


    rv.Initializer("rv").GridView(2).Vertical.Build

    Activity.AddView(rv , 0 , 0  , 100%x ,100%y)

    rv.DefaultAdapter

    Dim l As List
    l.Initialize
    adapter.Initialize
    For i = 1 To 10
        Dim item As item
        item.Initialize
        item.id = i
        item.title = "Item#" & i
        adapter.Put(item.id,item)
    Next
    rv.Adapter2.NotifyDataSetChanged
End Sub

Private Sub rv_GetItemCount As Int
    Return adapter.Size
End Sub

Private Sub rv_onCreateViewHolder (Parent As Panel,ViewType As Int)
    Dim p As Panel
    p.Initialize("")
    p.Color = Colors.RGB(Rnd(0,255) , Rnd(0,255) , Rnd(0,255))
    Parent.AddView(p , 0 , 0 , 50%x , 25%y)

    Dim l As Label
    l.Initialize("")
    l.Gravity = Gravity.CENTER
    l.TextColor = Colors.Black
    l.TextSize = 16
    p.AddView(l , 0 , 0 , -1,-1)

End Sub

Private Sub rv_onBindViewHolder (Parent As Panel,Position As Int)
    Dim item = adapter.GetValueAt(Position) As item

    Dim p As Panel = Parent.GetView(0)
    Dim l As Label = P.GetView(0)

    l.Text = item.title

    Parent.Tag = item
    Parent.Height = 25%y

End Sub

Private Sub rv_onItemClick (Parent As Panel,Position As Int)
    Dim item As item = Parent.Tag
    If adapter.ContainsKey(item.id) Then
        Dim index As Int = adapter.IndexOfKey(item.id)
    
        ' For delete an item from the grid
        adapter.RemoveAt(index)
        rv.Adapter2.NotifyDataItemRemoved(index)
    
        ' For refresh the grid for example to update the title of an item
        ' Firstly you should update the adapter
       '  item.title = "my new title here!"
       '  adapter.Put(item.id , item)
      '  rv.Adapter2.NotifyDataItemChanged(index)

        ' To add new item
        ' Dim nItem As item
        ' nItem.Initialize
        ' nItem.id = Rnd(1000,1000000)
        ' nItem.title = "My awesome title here!"
        ' adapter.PutAt(0, nItem.id , nItem)
        ' rv.Adapter2.NotifyDataItemInserted(0)
        ' rv.SmoothScrollToPosition(0)
    End If
End Sub
 

Attachments

  • sample2.zip
    8.6 KB · Views: 99
Last edited:

skaliwag

Member
Licensed User
I am still having problems getting the AX_RVFastScroller working correctly.
In the attached project, all I have done is added a large divider between the items in the provided sample.
As you can see, both the scrollbar and the pop-up are being drawn behind the divider.
Any ideas would be appreciated.
 

Attachments

  • FastScroll.png
    FastScroll.png
    12.9 KB · Views: 100
  • FastScroll.zip
    9.9 KB · Views: 89

alimanam3386

Active Member
Licensed User
I am still having problems getting the AX_RVFastScroller working correctly.
In the attached project, all I have done is added a large divider between the items in the provided sample.
As you can see, both the scrollbar and the pop-up are being drawn behind the divider.
Any ideas would be appreciated.

Define the FastScroller after the Recycler.DividerHorizontal...
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.Color = Colors.White
   
    Recycler.Initializer("Amir").ListView.Build
    Recycler.DividerHorizontal.Color(Colors.LightGray).Margin(0dip).Size(50dip).Build
   
    Dim FastScroller As AX_RVFastScroller
    FastScroller.Initialize("FastScroller",Recycler,500,Null)
    Activity.AddView(Recycler,0,0,100%x,100%y)
   
'    FastScroller.FastScrollAlwaysEnabled = True
    FastScroller.ThumbInactiveColor = 0xff999999
    FastScroller.ThumbactiveColor = 0xfff36807
    FastScroller.PopupBackgroundColor = 0xfff36807
    FastScroller.PopupTextColor = Colors.White
   
    CreateData
    Recycler.DefaultAdapter
End Sub
 

Inman

Well-Known Member
Licensed User
Could you please answer me on this thread?

 

User242424

Member
Licensed User
Hello World! i work on ARV wrappers team.
Let's start with an awesome ARV source code </>

AX_RVScalingParallax :

AX_RVScalingParallax.gif


Using AX_RVHeaderParallax plugin:
AX_RVHeaderParallax 1.00

Usage :
B4X:
'Initializing class
ScallingParallax.Initialize(Holder,Toolbar,RecyclerView)

'Add header content
Dim Img As ImageView
Img.Initialize("")
ScallingParallax.Content.AddView(Img,0,0,-1,-1)
Img.SetBackgroundImage(Bitmap)

'Customize items background
Dim CD As ColorDrawable
CD.Initialize(0xFF00D474,0)
ScallingParallax.Items.Background = CD

'Add items
AddItem("Watch Now",Chr(0xF26C))
AddItem("Comments",Chr(0xF0E5))

Private Sub AddItem (Text As String,Icon As Object)
    Dim Lbl As Label
    Lbl.Initialize("Item")
    Lbl.TextColor = Colors.White
    Lbl.Gravity = Gravity.CENTER
    
    Dim CS As CSBuilder
    CS.Initialize.Typeface(Typeface.FONTAWESOME).Size(20).Append(Icon).PopAll
    CS.Size(16).Append("  "&Text)
    Lbl.Text = CS.PopAll
    Lbl.Tag = Text
    
    ScallingParallax.AddItem(Lbl)
End Sub

Check the last email you have received and update your ARV package again..
you can find this source code on "Extra Samples"

the sample UI was inspired by ScalingLayout library.
 
Top