Hi,
I am just developing a custom control. In the control class I add a customlistview and its list items by code. I want to capture the event if the user clicks on a list row.
In the event sub I want to transfer the row value/index of the clicked list row to the main activity which loads the customcontrol as part of a layout.
I tried some solutions but nothing works. Please find attached my current code snipped. Can anyone help me how to answer the two questions of writing the code for the click event of the customlistview and the code for the index/value transfer to the parent activity. Thank you in advance.
Some codelines in B4A would help me.
Stay well and best regards
Guenter
I am just developing a custom control. In the control class I add a customlistview and its list items by code. I want to capture the event if the user clicks on a list row.
In the event sub I want to transfer the row value/index of the clicked list row to the main activity which loads the customcontrol as part of a layout.
I tried some solutions but nothing works. Please find attached my current code snipped. Can anyone help me how to answer the two questions of writing the code for the click event of the customlistview and the code for the index/value transfer to the parent activity. Thank you in advance.
Mainpart of customcontrol class:
Sub Class_Globals
Private mEventName As String 'ignore
Private mCallBack As Object 'ignore
Public mBase As B4XView
Private xui As XUI 'ignore
Public Tag As Object
Type TMI ( _
ID As Int, _
ParentID As Int, _
BM As Bitmap, _
Txt As String, _
Show As Boolean)
Private clv As CustomListView
Public ItemList As List
Private props1 As Map
End Sub
Public Sub Initialize (Callback As Object, EventName As String)
mEventName = EventName
mCallBack = Callback
'Scv.Initialize(100dip)
clv.Initialize(clv,"clv") <<<<<<<<<<< Is This is correct?
ItemList.Initialize
props1.Initialize
End Sub
'Base type must be Object
Public Sub DesignerCreateView (Base As Object, Lbl As Label, props As Map)
mBase = Base
Tag = mBase.Tag
mBase.Tag = Me
props1 = props
' set parameters
'.Width=mBase.Width
'Scv.height= mBase.height
mBase.AddView(clv.AsView,0,0,mBase.Width,mBase.Height) <<<<<<<<<<< Is This is correct?
End Sub
Private Sub Base_Resize (Width As Double, Height As Double)
End Sub
Sub buildBranch(item As TMI) As Panel
Dim t As Label ' Branch label
t.Initialize("ItemClicked")
t.Text = item.txt
If item.ParentID = 0 Then
t.Textcolor = props1.Get("ParentTextColor")
t.TextSize = props1.Get("ParentTextSize")
Else
t.Textcolor = props1.Get("ChildTextColor")
t.TextSize = props1.Get("ChildTextSize")
End If
t.Height = t.TextSize + 10
If item.ParentID <> 0 Then t.Tag = item.parentid
Dim ind As Label ' Intend
ind.Initialize("ItemClicked")
ind.Width = props1.Get("IntendWidth")
ind.Height = t.height
If item.ParentID <> 0 Then ind.tag = item.parentid
Dim i As ImageView ' Branch Image
i.Initialize("ItemClicked")
i.Height = t.Height
i.Width = i.Height
If item.ParentID <> 0 Then i.Tag=item.parentid
If item.bm.isinitialized Then i.Bitmap=item.bm
' stretch label to full width
t.Width =clv.asview.Width -10 - i.Width -10 -10
Dim p As Panel ' Main Branchpanel
p.Initialize("p")
p.RemoveAllViews
p.Height = t.height
If item.ParentID <> 0 Then p.Tag = item.parentid
If p.Height < i.Height Then p.Height=i.height
If p.Height < t.Height Then p.Height=t.height
If item.ParentID=0 Then
p.Color = props1.Get("ParentColor")
Else
p.Color = props1.Get("ChildColor")
End If
' add views to the panel
If item.ParentID = 0 Then
p.addview(i,10,0,i.Width,i.Height)
p.AddView(t,10 + i.Width + 10,0,t.Width,t.height)
p.Width = 10 + i.Width + 10 + t.width
Else
p.addview(ind,10,0,ind.width,ind.height)
p.addview(i,10 + ind.Width +10,0,i.Width,i.Height)
p.AddView(t,10 + ind.width + 10 + i.Width +10,0,t.Width,t.height)
p.Width = 10 + ind.Width + 10 + i.Width+10+t.width
End If
' return panel as tree row
Return p
End Sub
public Sub buildTree
Dim item As TMI
Dim p As Panel
p.Initialize("p")
clv.clear
For x = 0 To ItemList.Size-1
item = ItemList.Get(x)
'Log("V" & r & " " & item.Txt & " " & Scv.height)
p = buildBranch(item)
'Scv.Panel.AddView(p,0,r,p.Width,p.Height)
If item.Show = True Then clv.Add(p,p.Height,x)
Next
End Sub
Sub clv_ItemClick (Index As Int, Value As Object) <<<<<<<<<<<<<<< This is the not working event sub
CallSub(?????????) <<<<<< This should be the Transfer to the paren activity
End Sub
Some codelines in B4A would help me.
Stay well and best regards
Guenter