I modified the CustomListView example and added a LimitBar to each item panel. It displays fine. The problem is when any of the LimitBars is touched, it will call the CustomListView.GetItemFromView and throws an exception.
The exception is:
java.lang.RuntimeException: Method: getParent not found in: anywheresoftware.b4a.samples.customlistview.limitbar
That indicates to me the customlistview has no getParent sub to return its parent. So I added a getParent to limitbar and it never executes any line of code in that customlistview.getParent sub. Which means to me it still can't find the limitbar.getParent.
So before I spend too much more time on this, I have to ask:
1) Can a CustomListView contain a CustomView?
2) If yes, how do I get CustomListView.GetItemFromView() to work?
Note: I will be adding LimitBar to the panels dynamically later on instead of using the Designer. So if there is a solution it should work with the Designer and at runtime.
TIA
B4X:
'Returns the index of the item that holds the given view.
Public Sub GetItemFromView(v As View) As Int
Dim parent = v, current As Object
Do While (parent Is Panel) = False Or sv.Panel <> parent
current = parent
Dim jo As JavaObject = current
parent = jo.RunMethod("getParent", Null) '<-- Throws exception
Loop
v = current
Return v.Tag
End Sub
The exception is:
java.lang.RuntimeException: Method: getParent not found in: anywheresoftware.b4a.samples.customlistview.limitbar
That indicates to me the customlistview has no getParent sub to return its parent. So I added a getParent to limitbar and it never executes any line of code in that customlistview.getParent sub. Which means to me it still can't find the limitbar.getParent.
So before I spend too much more time on this, I have to ask:
1) Can a CustomListView contain a CustomView?
2) If yes, how do I get CustomListView.GetItemFromView() to work?
Note: I will be adding LimitBar to the panels dynamically later on instead of using the Designer. So if there is a solution it should work with the Designer and at runtime.
TIA
B4X:
private fParent as Object
public Sub getParent(v As View) As View
Private jo As JavaObject
If v.IsInitialized Then
Return jo.RunMethod("getParent", Null)
Else
Return fParent
End If
End Sub
Public Sub DesignerCreateView(Base As Panel, Lbl As Label, Props As Map)
Private r As Reflector
r.target = Base
fParent = r.RunMethod("getParent")
....
end sub
Public Sub AddTpParent(Parent As Activity, Left As Int, Top As Int, Width As Int, Height As Int, cColor As Int, cRadius As Int)
cLeft = Left
cTop = Top
cWidth = Width
cHeight = Height
fParent = Parent
....
end sub