Android Question Exmple Using RecyclerView Lib

syerif

Member
Licensed User
Hi, Everyone

can anyone provide a sample code program using the RecyclerView library (not amir-RecyclerView)
upload_2019-6-29_14-29-30.png
 

syerif

Member
Licensed User
I got it in another forum, I assume that the library is from this forum.


after I tried it I finally found this

B4X:
#Region  Project Attributes
    #ApplicationLabel: RecyclerView
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

#AdditionalRes : ..\res
#AdditionalJar: com.android.support:support-v4
#BridgeLogger: True

Sub Process_Globals
    
End Sub

Sub Globals
    Dim re As RecyclerView
    Dim jo As JavaObject
    Private img As ImageView
    Private lbl As Label
    Private btn As Button
    Dim lbl2 As Label
    Dim img2 As ImageView
    Dim btn2 As Button
    Dim Items As List
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.Color = Colors.White
    jo.InitializeContext
    Items.Initialize
    Items.AddAll(Array As String("Item1","2222","Sevom","Ch","55","66666","7777","8888","LastItem"))
    Activity.AddView(re.Initialize("Recycler",jo.RunMethod("Layout",Null),Items.Size),0,0,100%x,100%y)
    're.SpanCount = 2
    lbl2.Initialize("")
    img2.Initialize("")
    btn2.Initialize("")
End Sub

Sub Activity_Resume
    
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    
End Sub

Sub Recycler_onCreateItem(V As Object, Position As Int)
    Dim p As Panel = V
    If p.NumberOfViews = 0 Then
        Dim p2 As Panel : p2.Initialize("p2")
        re.AddViewToParent(p,p2)
'        Dim j As JavaObject = V
'        p2.Height = j.RunMethod("getWidth",Null)
'        p2.Color = Colors.RGB(Rnd(0,255),Rnd(0,255),Rnd(0,255))
        p.Height = 60dip
        p2.LoadLayout("l2")
    End If
    For Each View1 As View In p.GetAllViewsRecursive
        If GetType(View1) = GetType(lbl) Then
            lbl2 = View1
            lbl2.Text = Items.Get(Position)
        Else If GetType(View1) = GetType(img) Then
            img2 = View1
            img2.Bitmap = LoadBitmap(File.DirAssets,(Position+1) & ".png")
            img2.Left = 100%x - 60dip
        Else If GetType(View1) = GetType(btn) Then
            btn2 = View1
            btn2.Tag = Position
            btn2.Text  = Position + 1
        End If
    Next
End Sub

Sub p2_Click
    Dim p3 As Panel = Sender
    ToastMessageShow("Item Clicked At #"&re.GetPosition(p3.Parent),False)
End Sub

#If JAVA
    public int Layout(){
        return R.layout.recycler_layout;
    }
#End If

Sub btn_Click
    Dim b As Button = Sender
    ToastMessageShow("Button Clicked At #"& (b.Tag+1),False)
End Sub
 
Top