Android Question Identifying programatically created panels

Fusseldieb

Active Member
Licensed User
Longtime User
Hi all,
I have a problem.
I am adding panels with labels inside. These panels are all inside a ScrollView and when the user reaches the final of the "list", it catches more items on the database and adds more panels...
Now I want to click on one of these labels to read the details of this item. But how can I "index" each panel, so that I can retrieve the right item?

The "Panel_Touch" sub doesn't help me much, because he has no ID or something to identify which panel it is.
It has only "Action", "X" and "Y".

Thanks in advance ;)
 

LucaMs

Expert
Licensed User
Longtime User
Set the same Event Name (like "Item") for each Panel and an ItemID in the Tag of the Panel.
Then in the Click event put something like:
Sub Item_Click
private pnl as Panel = Sender
private ID as int = pnl.Tag
End Sub

You could use CustomListView or CheckList instead of ScrollView.
 
Last edited:
Upvote 0

Xicu

Active Member
Licensed User
Longtime User
I use the tag panel property to index each panel that I create

B4X:
    Dim P As Panel
    P.Initialize("Preference")
    svPrincipal.Panel.AddView(P, 0, svHeight, svPrincipal.Panel.Width, ItemHeight)
    P.Tag = "Index" '(A single number or text)
.....

And at the event ...

B4X:
Sub Preference_Touch (Action As Int, X As Float, Y As Float) As Boolean
'Return True to consume the event
    'Save the selected value panel
    Dim SelectedPanel as panel
    SelectedPanel = Sender
    Select Case SelectedPanel.Tag
        Case "Index"
             Msgbox(SelectedPanel.Tag,"Panel Selected")
    End Select
End Sub
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Using one of the two classes that I have mentioned, everything becomes easier.

Build your Item in a routine and add it to the ScrollView inside the class; just follow the examples attached to the relative threads.
 
Upvote 0
Top