Public Sub AddToParent(Parent As Panel, Left As Int, Top As Int, Width As Int, Height As Int)
Parent.AddView(mBase, Left, Top, Width, Height)
cvs.Initialize(mBase)
' Set parent color based on parent background
Try
If Parent Is Panel Then
Dim p As Panel = Parent
mParentColor = p.color '<==Error code
End If
Catch
Log("Could not get parent panel color")
End Try
End Sub
I'm ok. I found the old code may be solved the problem. Thank you,Cableguy
B4X:
'In CustomView Class
Public Sub GetParentColorIs As Int
Try
If mBase.Parent=Null Then Return xui.Color_White
Dim jo As JavaObject=mBase.Parent
'Check field color
If HasField(jo,"color") Then
Return jo.GetField("color")
End If
Catch
Log("Get parent color failed" & LastException.Message)
End Try
Return xui.Color_White
End Sub
'Check Field
Private Sub HasField(jo As JavaObject,fieldName As String) As Boolean
Try
Dim cls As JavaObject=jo.GetField("java.lang.Object.class")
Dim fields() As Object= cls.RunMethod("getDeclaredFields",Null)
For Each field As JavaObject In fields
Dim name As String=field.RunMethod("getName",Null)
If name=fieldName Then
Return True
End If
Next
Catch
Log(LastException)
End Try
Return False
End Sub
The color attribute of a panel is WRITE only, meaning you cannot read it... you will need to come up with a different way to retrieve it... like retrieving a pixel color
Yes, I've tried to create CustomView. Assume If I paste the customview on the panel or non-panel , how to get the parent's color. But I don't make sure what strategy get
be perfectly.
I think that you are not showing all the code of the AddToParent routine in the first post.
You add mBase, but it is not initialized or created.
You should use B4XPages and as much as possible B4XViews.
B4X:
Public Sub AddToParent(Parent As B4XView, Left As Int, Top As Int, Width As Int, Height As Int)
mBase = xui.CreatePanel("")
Parent.AddView(mBase, Left, Top, Width, Height)
cParentColor = Parent.Color
End Sub
I'm studying the customview about progressbar. The percent of number is on the panel, or not, I can't predict, so I must check theproject has panel, ornot.I don't understand your code at the line why we have to create again.If the project doesn't have panel, how to code it.
I'm ok. I found the old code may be solved the problem. Thank you,Cableguy
B4X:
'In CustomView Class
Public Sub GetParentColorIs As Int
Try
If mBase.Parent=Null Then Return xui.Color_White
Dim jo As JavaObject=mBase.Parent
'Check field color
If HasField(jo,"color") Then
Return jo.GetField("color")
End If
Catch
Log("Get parent color failed" & LastException.Message)
End Try
Return xui.Color_White
End Sub
'Check Field
Private Sub HasField(jo As JavaObject,fieldName As String) As Boolean
Try
Dim cls As JavaObject=jo.GetField("java.lang.Object.class")
Dim fields() As Object= cls.RunMethod("getDeclaredFields",Null)
For Each field As JavaObject In fields
Dim name As String=field.RunMethod("getName",Null)
If name=fieldName Then
Return True
End If
Next
Catch
Log(LastException)
End Try
Return False
End Sub
I tried your HasField function and got an error on line
B4X:
Dim cls As JavaObject=jo.GetField("java.lang.Object.class")
error: java.lang.RuntimeException: Field: java.lang.Object.class not found in: anywheresoftware.b4a.BALayout
Am I missing something in the manifest, jar, etc?
What is mBase for you ?
Where do you declare and initialize mBase ?
To be able to better help you, you must post your project, so we can see what you have done.
What is mBase for you ?
Where do you declare and initialize mBase ?
To be able to better help you, you must post your project, so we can see what you have done.
My CustomView is from SDDust's liquidProgress gress inspiration. I think that mBase can be Activity (As Non-CrossPlatforms) or B4XPage.main (As CrossPlatforms)