Android Question Customview

stevenindon

Active Member
Licensed User
Hi all,

I have created a customview (Custom view with a loaded designer form - mBase.LoadLayout("imageslider"))
Here are the code example :

B4X:
***** CODES IN CUSTOM VIEW ******
Public Sub Displaynow()
...
...
End Sub

***** CODES IN PARENT ******
Mycustomview.Displaynow


When i call Mycustomview.Displaynow(), list of error fro B4A indicates as such:


Error occurred on line: 74 (ImageSlider)
java.lang.RuntimeException: Object should first be initialized (HorizontalScrollView).
Did you forget to call Activity.LoadLayout?
at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:67)
at anywheresoftware.b4a.objects.HorizontalScrollViewWrapper.getPanel(HorizontalScrollViewWrapper.java:67)
...
...
...

Can we actually call our own Sub procedure in customeview from the parent?

Thanks

Regards,

Steven
 

Dev-i9

Member
without seeing more code than the one you show, I guess no one will be able to help you more than answering your question directly: YES, you can call your own customvies subs... dig a bit more inside this forum and use the search function... It really does work wonders
 
Upvote 0

stevenindon

Active Member
Licensed User
Hi and thank you Klaus for your prompt reply. Please find attached customview in B4A folder - (.rar or .zip) *Both are the same
 

Attachments

  • B4A_Imageslider.rar
    374.8 KB · Views: 125
  • B4A_Imageslider.zip
    406.9 KB · Views: 140
Last edited:
Upvote 0

klaus

Expert
Licensed User
Longtime User
The problem is that you define :
Private ImageSlider As ImageSlider
But, in the Designer it is called ImageSlider1 !!!
Replace ImageSlider by ImageSlider1 and it will work as you expect it to work.
You must NOT initialize ImageSlider because you load a layout.

The code below works.
It took me a while to find it :).

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private ImageSlider1 As ImageSlider
End Sub

Public Sub Initialize
    B4XPages.GetManager.TransitionAnimationDuration = 0
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")
'    ImageSlider.Initialize(Root,"ImageSlider")
    ImageSlider1.GetAllImages ' <<------- ERROR IF I CALL FROM HERE !!!!!!!!!!!!!!!!!!!!!
    ' IT WORKED IF I CALL INSIDE IMAGESLIDER AfterLoadLayout
End Sub
 
Last edited:
Upvote 0

stevenindon

Active Member
Licensed User
Thank you klaus. It has been my mistake for noticing the name in the object.

'You must NOT initialize ImageSlider because you load a layout.' - I did that because of the error... haa haaa silly me

Thank you so much klaus. You have been great!
 
Upvote 0
Top