Android Question Is it possible to create a custom view based on another custom view?

narbe13

Member
Licensed User
Hello,

I'm trying to create a family of custom views:

HorizontalSegment is a panel (width 20, height 10) with some methods (TurnOn, TurnOff...)

Verticalsegment is a HorizontalSegment with different size (width 10, height 20), and inherits the methods of HorizontalSegment

DigitalPoint is a customised VerticalSegment ...

I read in the UserGuide.pdf, section 12.4 that "With classes you can add your own custom views which can be based on standard views but with more functions"

Does this mean that a custom view CANNOT be based on a Custom view?

Can anybody help?

Thank you!

Bernard
 

narbe13

Member
Licensed User
Thank you for your reactivity!

How can I tell the compiler what the base type is (standard Viewbutton, label... or custom view)?

I can't find this info.

Thank you

Bernard
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
That you cannot!
In b4a a custom view will always be based on a Panel, which is also the base container if the custom view. Along with it, and to accommodate text properties, you have a label that you can choose how to use it, or not at all.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
For a Custom View you should have a base panel.
Then you add other views onto this panel.
If you add a Custom View you define it with its type.
But this Custom View must have a routine to add it via code like
AddToParent(Parent As Panel, Ledt As Int, Top As Int, Width As Int, Height As Int)
Example you want to add MyCustomButton custom view to the new one.
B4X:
Private NewButton as MyCustomButton
NewButton.AddToParent(pnlBase, 0, 0, 100dip, 50dip)
This code DOESN'T work:
B4X:
Private NewButton as MyCustomButton
pnlBase.AddView(NewButton, 0, 0, 100dip, 50dip)
 
Upvote 0
Top