Android Question Views in CustomListView events

GiovanniPolese

Well-Known Member
Licensed User
Longtime User
Hi to all
I have a CustomListView. On each line (row) of it I have put a small panel. "col". The CustomListView shows some items and the small Panel "col" on each line represents the color of each item. Each panel col is initialized with an event and has the Tag property set to the CustomListView row. The question is: is it possible to get the CustomListView row only clicking the small Panel "col" (on each line of the List), firing its event? Of course I can select the row in the ListView. but the idea is to by-pass selecting the ListView row, only clicking the Panel in its rows. This happens if I have no event in the Col, because the Click on the col panel is passed to its parent (i guess). But if the col panel has its own event, I don't see the possibility to get the ListView row. The attached code explains my question, I hope.
B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private CustomListView1 As CustomListView
End Sub

Public Sub Initialize
'    B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")

End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Private Sub Button1_Click
    'xui.MsgboxAsync("Hello world!", "B4X")
    For i = 0 To 10
        Dim p As B4XView = xui.CreatePanel("")
        p.SetLayoutAnimated(0, 0, 0, 100, 50dip)
        Dim col As Panel

        col.Initialize("col") ' if this event is defined, the ListView_ItemClick is not fired, if not defined it is
        col.Color=Colors.Black
        col.Tag=i
        p.AddView(col,CustomListView1.AsView.Width-60dip, 0dip, 50dip, 50dip)

        CustomListView1.Add(p, i)
    Next
End Sub

Sub col_click
 Log("Col fired")    ' the question is: can we get the ListView row here
End Sub

Sub CustomListView1_ItemClick (Index As Int, Value As Object)
    Log(Value)
End Sub
 

Attachments

  • TestX.zip
    10.4 KB · Views: 54

Sagenut

Expert
Licensed User
Longtime User
Modify in this way
B4X:
Sub col_click
    Log("Col fired")
    Dim p As Panel = Sender   'Set a temporary reference to the clicked Black Panel to access the properties
    Log("You clicked the Black Panel on Item Number " & p.Tag)
End Sub
*** EDIT ***
A better option is shown in the next post
 
Last edited:
Upvote 0

Sagenut

Expert
Licensed User
Longtime User
Also I suggest you another modify to have the Black Panel Tag property free for some other data
B4X:
Sub col_click
    Log("Col fired")
    Dim ClickedView As B4XView = Sender  'Set a reference to the clicked Black Panel to access the properties
    Log("You clicked the Black Panel on Item Number " & CustomListView1.GetItemFromView(ClickedView)) 'Retrieve the Item Number from the Black Panel
End Sub
In this way it's not needed to assign the item number to col.Tag
You can leave it empty or use it for something else.
 
Upvote 1
Top