Android Question Amir_RecyclerView question

Jones Hone

Member
Licensed User
I am testing Amir_RecyclerView
How to press btnADD to change the content of lblQTY.Text.
Thank you very much.

Below is the code:
B4X:
#Region  Project Attributes
    #ApplicationLabel: RVTest02
    #VersionCode: 2
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
    #Extends: android.support.v7.app.AppCompatActivity
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private Recycler As Amir_RecyclerView
    Private PLUItems As List
    Dim Image As ImageView
    Dim Glide As Amir_Glide
    Dim btnADD As Button
    Dim lblQTY As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
    PLUItems.Initialize
    PLUItems = LoadDataOfKind
    Recycler.SetRecyclerViewStyle("VerticalScrollbarRecyclerView")
    Recycler.Initializer("Recycler").ListView.StackFromEnd(False).Build
    Activity.AddView(Recycler,0,0dip,100%x,100%y)
    Recycler.ScrollToEndListener(False)
    Dim Adapter As Amir_RVAdapter
    Adapter.Initialize("Recycler",Adapter.LOOP_NEVER)
    Recycler.Adapter = Adapter
End Sub

Sub Activity_Resume
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Recycler_onCreateViewHolder (Parent As Panel,ViewType As Int)
    Parent.Height = 300dip
    Dim SectionHolder As Panel
    SectionHolder.Initialize("SectionHolder")
    Parent.AddView(SectionHolder, 2dip, 3dip, Parent.Width - 4dip,292dip)

    Image.Initialize("Image")
    Image.Gravity = Gravity.FILL
    Dim w As Long  = SectionHolder.Width /4*3
    SectionHolder.AddView(Image,4dip,4dip,W,w*3/4)

    btnADD.Initialize("btnADD")
    btnADD.Text ="+"
    btnADD.TextSize = 32
    btnADD.TextColor  = Colors.Red
    btnADD.Padding = Array As Int (0,0,0,0)
    SectionHolder.AddView(btnADD,0,0,90dip,90dip)

    lblQTY.Initialize("lblQTY")
    lblQTY.Text ="0"
    lblQTY.TextSize = 24
    SectionHolder.AddView(lblQTY,0,0,60dip,60dip)
    SectionHolder.Height = Image.Top +Image.Height
    Parent.Height= Image.Top +Image.Height +6dip
End Sub

Sub Recycler_onBindViewHolder (Parent As Panel,Position As Int)
    Dim data As Map = PLUItems.Get(Position)
    Dim SectionHolder = Parent.GetView(0) As Panel
    Dim Image = SectionHolder.GetView(0) As ImageView
    Dim btnA = SectionHolder.GetView(1) As Button
    Dim lblQ = SectionHolder.GetView(2) As Label
  
    Dim L As Long = Image.Left + Image.Width
    btnA.SetLayout( L +  (SectionHolder.Width-L-50DIP)/2  ,Image.Top+(Image.Height -Image.Top -50dip)/2 ,50dip ,50dip)
    lblQ.SetLayout( btnA.Left+12dip ,btnA.Top + btnA.Height+8dip,120dip ,40dip)
  
    Glide.Initializer.Default
    Image.Tag = Null
   Glide.LoadWith.URI("file:///android_asset/" & data.Get("image")).Apply(Glide.RO.CenterCrop.DiskCacheStrategy("RESOURCE")).Into(Image)

    btnA.Tag = Position
End Sub

Sub Recycler_GetItemCount As Int
    Return PLUItems.Size
End Sub

 Sub LoadDataOfKind As List
    Dim mData As List,i As Int
    mData.Initialize
    For i=1 To 6
        mData.Add(CreateMap("image": "p" & i & ".jpg"))
    Next
    Return mData
End Sub

Sub btnADD_Click
    Dim obj = Sender As Button
    Log(obj.Tag)
    'How to press btnADD to change the content of lblQTY.Text.
End Sub
 

Attachments

  • pic.jpg
    pic.jpg
    237.3 KB · Views: 105

Jones Hone

Member
Licensed User
I tested successfully! Can do this:
B4X:
Sub btnADD_Click
    Dim obj = Sender As Button
    Dim pp As Panel = obj.Parent
    Dim lbl  = pp.GetView(2) As Label
    Dim aa = lbl.Text As Long
    lbl.Text = aa + 1
End Sub
But can't keep value!!
When scrolling, it will become 0 again.
 
Last edited:
Upvote 0
Top