B4A Library [Lib, Chargeable] Amir_RecyclerView

sigster

Active Member
Licensed User
Longtime User
Hi

how can I get item / text

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

alimanam3386

Active Member
Licensed User
Longtime 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
Longtime 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:




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




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
Longtime 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
Longtime 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
Longtime User
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
 

alimanam3386

Active Member
Licensed User
Longtime User
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

No worries.
 

skaliwag

Member
Licensed User
Longtime 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
Longtime 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
Longtime 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
 

itgirl

Active Member
Licensed User
Longtime User
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
Longtime User

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
Longtime 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
Longtime 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: 319
  • 3462423.jpg
    12.7 KB · Views: 336
Last edited:

Inman

Well-Known Member
Licensed User
Longtime 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
Longtime 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 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: 315
Last edited:

skaliwag

Member
Licensed User
Longtime 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
    12.9 KB · Views: 304
  • FastScroll.zip
    9.9 KB · Views: 295

alimanam3386

Active Member
Licensed User
Longtime User

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
Longtime 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 :



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.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…