Android Question xCustomListView get Panel id

Declan

Well-Known Member
Licensed User
Longtime User
I am using this example:
I have changed the name of the 2 X Buttons.
What I need to achieve is to read the Panel Id when one of the two Buttons are Clicked
Then action the Button function to Accept or Reject - On Reject, I must delete the item from the list
I have tried the following to get panel id:
B4X:
Sub btnAccept_Click
    Dim v As Button
    v = Sender
    Dim MyIndex As Int
    Dim MyIndex = clv1.GetPanel(v)
    LogColor("Button Accept: " & MyIndex, Colors.blue)
End Sub
How do I read the lblTitle.text of a panel on the Button_Click event
I always get :Item# 20" - the last item in the CustomListView, not the Item that I Clicked
 
Last edited:

Declan

Well-Known Member
Licensed User
Longtime User
@LucasM - Thanks
However, when I run:
B4X:
Sub btnAccept_Click
    Dim v As Button
    v = Sender
    Dim Index As Int = clv1.GetItemFromView(Sender)
    Dim pnl As Panel = clv1.GetPanel(Index)
    Dim MyIndex  As String = Index
    Dim MyPanel As String = pnl

    LogColor("Button Accept: " & v.text & "Index: " & MyIndex & "Text; " & "Panel: " & MyPanel & "Text; " & lblTitle.text, Colors.blue)
    CollapseItem(MyExpandedID)
It always returns "Item #20" and not the actual Panel Title text that the Button is in:
B4X:
Button Accept: AcceptIndex: 1Text; Panel: (BALayout): Left=0, Top=0, Width=1080, Height=420, Tag=trueText; Item #20
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
The attached project is an edited version of the example in post 1.
In my main project, I am using Firebase notifications.
The "Title" and "Body" of the Firebase notification message is comma delimited and includes a unique ID.
When the Firebase message is received, it is loaded into the CustomListView and the user has the option to Accept or Reject the notification (btnAccept / btnReject)
If the user clicks btnAccept, I parse the notification string and write to SQLite table. Therefore, I must be able to read the full Text in the CustomListView
If the user clicks btnReject, I simply remove the CustomListView item.
I hope this makes sense
 

Attachments

  • 1.zip
    15.5 KB · Views: 148
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Remove CustomListView class. Add CLVExpanded and xCustomListView library.
Ok, Done
Result is the same
Latest project with CLVExpanded and xCustomListView library.
 

Attachments

  • 1.zip
    11.8 KB · Views: 140
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Result is the same
That's expected.
lblTitle will point to the last one that was added.

I wanted to show you how to fix the code however I can't as you haven't implemented CLVExpandable correctly.
 
Upvote 0

Declan

Well-Known Member
Licensed User
Longtime User
Ok, Done.
The attached project runs.
btnReject_Click works and removes the item from the list
 

Attachments

  • 2.zip
    11.4 KB · Views: 153
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1:
B4X:
For i = 1 To 20
        Dim Title As String = "Item #" & i
        Dim p As B4XView = CreateItem(Rnd(0xFF000000, 0xFFFFFFFF), Title, Rnd(100dip, 250dip) + 60dip)
        clv1.Add(p, expandable.CreateValue(p, Title))
    Next
2:
B4X:
Sub btnAccept_Click
    Dim Index As Int = clv1.GetItemFromView(Sender)
    Dim text As String = expandable.GetValue(Index)
    Log(text)
End Sub
If you need to store more information then use a custom type or array.
 
Upvote 0

Pere Vinyes

Member
Licensed User
Longtime User
By the way: say a xCustomListview (CLV1) that contains a layout.pnl (p.LoadLayout("Items3") containing another xCustomListview (CLV2) that have a Checkbox (CHK1). All works as expected and a click on CHK1 is correctly fired. The question is: How may I read the status of CHK1 and the index of CLV1 and CLV2 of the CHK1 clicked?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…