Android Question How To use customview as a generic view

Asim A Baki

Active Member
Licensed User
Longtime User
I have made a custom view and I try to add it to the activity.addview and I face type mismatch issue

I thought customview never be a view until I saw SimpleExoPlayerView which is a custom view and it is added normally to activity.addview

I need to add the customview to the activity not the Base because I laterly use findview to get the view from the activity and use it's custom properties
 

Asim A Baki

Active Member
Licensed User
Longtime User
You need to add a routine (AddToParent for example) in the Class allowing to add the CustomView in the code.

Did you have a look at the B4x CustomViews Booklet, link in my signature?
There you find examples.

I have Added it already but it only allow me to add the base panel to the activity, while I need the complete control to be able to access it again with findview
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I tested it, it's possible!
You should add a routine to get the base panel, even like a Propety, if it doesn's exist.
I tested it like this.
B4X:
Public Sub getPanel As Panel
    Return BasePanel ' name depends on your code
End Sub

Then in the calling module:
MyCustomView.Panel.NumberOfViews works.
For Each v As View In MyCustomView.Panel.GetAllViewsRecursive works
For Each v As View In Acticity.GetAllViewsRecursive works, and finds all the views in the CustomView.
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
I still need to catch the custom view itself not the children views

The code you offer is for catching contained views in the custom view panel
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
Sorry, I do not understand.
What do yo mean with custom view itself?
The CustomView is only known by it's main Panel.
You can define the properties of the CustomView with getXXX and setXXX routines.
XXX will be considered as a Property.
The you can access it with MyCustomView.XXX.
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
I have developed a library which contains auto scrolling CutomView, any controls or text added to the CustomView with the method ScrollingPanel1.AddObject is added and auto scrolled https://www.b4x.com/android/forum/threads/scrolling-panel.85519/


I need to be able to add multiple ScrollingPanels at runtime and access them with findview to add more text and call ScrollingPanel1.AddObject
If I just added the ScrollingPanel1.base panel to the activity I wouldn't be able to access the method ScrollingPanel1.AddObject because it belongs to the customview not the base panel. and Findview would only return the basepanel

if there is a way to get the customView from it's basepanel that would work
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
I've done something similar in my MultiRowTabPane library (It's for B4j but the method will work for B4a). Create the panel in the calling activity or class then pass it to the customview to add it.

You will need to keep a reference to the panel as a global variable if you want to change it after adding, and any callbacks will come directly to the calling module.
 
Upvote 0

Asim A Baki

Active Member
Licensed User
Longtime User
yeah, it looks that I have to keep global map for the runtime created views and customviews to be able to access them later, which is not the elegant way, but It may work
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
It could be possible to get the library to add the panel and handle the callbacks. But it would mean handling every possible type of callback if you don't know what is going to be added. And if a customview is added, you won't know what the events will be.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…