Android Question Custom List View inside Custom List View

Carlos Muniz

Member
Licensed User
Longtime User
Hi:
I have a problem. My App has one vertical CLV populated with several horizontal CLV. Inside the horizontal CLV I have buttons, labels and one image view. I want to click in one of those
buttons (Sender) and get their tag. The code bellow is for one CLV. Works fine, but for several CLV inside that it dosn't works.

B4X:
    Index = clvStores.GetItemFromView(Sender)
    pnl = clvStores.GetPanel(Index)
    lbl = pnl.GetView(5)        ' btnYES
    lbl1 = pnl.getview(6)        ' btnNO

I can't address on button inside tany horizontal CLV.
Can someone help me ?
 

Carlos Muniz

Member
Licensed User
Longtime User
You might get some help from one of the members if you export a small project because your post is a little bit hard to understand, at least for me and appears to be a little more involved.
Hi:

I have one vertical CLV populated with several horizontal CLV. The horizontal CLV has several panels with buttons, labels etc. How can I discover what button was clicked ?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Here is an example that works, but as @Mahares said, it may not be what you want.
If you don't use B4XPages just put the loop in Activity_Create


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")     'has vertical clv anchored top and bottom
    For i = 1 To 13
        addRow(i)
        Sleep(20)
    Next
End Sub

Private Sub addRow(rowIndex As Int)
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl.SetColorAndBorder(xui.Color_Transparent, 1dip, xui.Color_Black, 5dip)
    pnl.SetLayoutAnimated(0, 0, 0, 600dip, 100dip)
    pnl.LoadLayout("hclv")            'has horizontal clv anchored all sides
    Sleep(20)
   
    CustomListView2.Add(newItem(rowIndex, 1, "Item1"), 0)
    CustomListView2.Add(newItem(rowIndex, 2, "Item2"), 0)
    CustomListView2.Add(newItem(rowIndex, 3, "Item3"), 0)
    CustomListView2.Add(newItem(rowIndex, 4, "Item4"), 0)
    CustomListView2.Add(newItem(rowIndex, 5, "Item5"), 0)
    CustomListView2.Add(newItem(rowIndex, 6, "Item6"), 0)
    CustomListView2.Add(newItem(rowIndex, 7, "Item7"), 0)
    CustomListView2.Add(newItem(rowIndex, 8, "Item8"), 0)

    Sleep(20)
    CustomListView1.Add(pnl, 1)
End Sub

Private Sub newItem(rowIndex As Int, colIndex As Int, s As String) As B4XView
    Dim btn As Button
    btn.Initialize("btn")
    Dim btnx As B4XView = btn
    btnx.SetTextAlignment("CENTER", "CENTER")
    btnx.Text = s
    btnx.Tag = Array As Int(rowIndex, colIndex)
    Dim pnl As B4XView = xui.CreatePanel("")
    pnl = xui.CreatePanel("")
    pnl.SetColorAndBorder(xui.Color_Transparent, 1dip, xui.Color_Black, 5dip)
    pnl.SetLayoutAnimated(0, 0, 0, 90dip, 100dip)
    pnl.AddView(btnx, 0, 0, 90dip, 100dip)
    Return pnl   
End Sub

Private Sub btn_Click
    Dim btnx As B4XView = Sender
    Dim ar() As Int = btnx.tag
    Log(btnx.Text & TAB & ar(0) & TAB & ar(1))
End Sub


Private Sub CustomListView1_ItemClick (Index As Int, Value As Object)  'Not needed
End Sub

Private Sub CustomListView2_ItemClick (Index As Int, Value As Object)  'Not needed
End Sub
 
Upvote 0
Top