Wish Custom Views

iCAB

Well-Known Member
Licensed User
Longtime User
When I first started developing using B4A tools, we had to build the GUI in code to provide the most flexible approach for resizing, positioning and future portability.

Now I find myself at a great disadvantage not being able to use Custom Views with existing layouts that are built in code.

I wish there is some sort of workaround that will allow us to to use custom b4x views with existing implementations,

I would suggest that you implement a workaround for that to support those that are facing the same issues as me.

As an example:
  • you make it the responsibility of the user to link the proper class
  • Maybe the custom view must be declared using the designer in some hidden layout and then copied via code to a different panel, etc
Whatever works, would be greatly appreciated.

I am sure it's not impossible for someone like Erel :)

Thank you
iCAB
 

LucaMs

Expert
Licensed User
Longtime User
When I first started developing using B4A tools, we had to build the GUI in code to provide the most flexible approach for resizing, positioning and future portability.
I guess that b4a has always had the Designer - although without Anchors.

Now I find myself at a great disadvantage not being able to use Custom Views with existing layouts that are built in code.
I don't understand what you mean; a custom view is based on a panel, so if you want "play" with it by code in some "strange" manner, you should use this panel.
The only important thing, I think, is that custom views should be created to be also added by code, not only in the Designer, and this is a choice of the developer who creates the custom view.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There is really no reason to create the complete layout by code. This is true in B4A and especially true in B4i and B4J where the visual designer takes care of page size changes.

With that said you can easily add custom views to your layout. Create a layout file with the custom view and load it whenever you like to add it.
 

iCAB

Well-Known Member
Licensed User
Longtime User
I guess that b4a has always had the Designer - although without Anchors.

That is true, but also auto resizing all controls based on screen resolution & orientation, was an issue.
We built the layout in code to support orientation, resizing etc
Also the exact same layout (Code) that we have today, works equally for B4A and B4I

I don't understand what you mean; a custom view is based on a panel, so if you want "play" with it by code in some "strange" manner, you should use this panel.
The only important thing, I think, is that custom views should be created to be also added by code, not only in the Designer, and this is a choice of the developer who creates the custom view.

I think you misunderstood what I am saying.
If I am creating my own custom view... no problem.. I am responsible for all of it.
But I would like to use the existing B4X custom views and be able to add them to my existing layouts with code ( as simple as using the designer, or adding any standard controls with code).

The reference threads always say, must be added with the designer (there must be a good reason for that)
 

LucaMs

Expert
Licensed User
Longtime User
That is true, but also auto resizing all controls based on screen resolution & orientation, was an issue.
To me it is still hard :D


This is sure:
I think you misunderstood what I am saying.
I don't understand what you mean


The reference threads always say, must be added with the designer (there must be a good reason for that)
There are CV created to be added both by Designer and by code.
 

iCAB

Well-Known Member
Licensed User
Longtime User
There is really no reason to create the complete layout by code. This is true in B4A and especially true in B4i and B4J where the visual designer takes care of page size changes.
With that said you can easily add custom views to your layout. Create a layout file with the custom view and load it whenever you like to add it.

I trust what you are saying (as always :) ), since I never really experimented with the designer as we already built the solution at a certain point.

However as an example:
Currently I am using the exact same code to build my layouts(except for the low level code that actually creates the control) . All layouts work exactly the same for B4A and B4I. For a large app, it makes a difference to share layout files between platforms.

Nothing urgent, but would it be possible to provide some sample code that shows how to properly add a custom view in code. May be for something like:
https://www.b4x.com/android/forum/t...-cross-platform-customlistview.84501/#content
 

iCAB

Well-Known Member
Licensed User
Longtime User
To me it is still hard :D
This is sure:
There are CV created to be added both by Designer and by code.

Here is what I am referring to
B4XComboBox class is a wrapper for B4J ComboBox, B4A Spinner and B4i Button + ActionSheet.
It is implemented as a custom view and should be added with the designer.
 

moster67

Expert
Licensed User
Longtime User
Create a layout file in the designer and add your custom view to it or any other custom view Save the layout as usual, In your code you add a panel and use its layout method to add the just created layout It should work.
 

iCAB

Well-Known Member
Licensed User
Longtime User
add the just created layout It should work.
Interesting one.. then what is the purpose of this statement:

"It is implemented as a custom view and should be added with the designer.". There must be a reason
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Sub SpecialSubThatCreatesACustomViewProgrammatically (Parent As Panel, Left As Int, Top As Int, Width As Int, Height As Int)
 Parent.LoadLayout("LayoutWithOnlyTheCustomViewMakeSureThatHandleResizeEventIsUnchecked")
 Dim v As View = Parent.GetView(Parent.NumberOfViews - 1)
 v.SetLayoutAnimated(0, 1, Left, Top, Width, Height)
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
BTW, if you need access to the custom view class instance then you should add a global variable with the same name as the view and it will hold a reference to the last loaded custom view:
B4X:
Sub SpecialSubThatCreatesACustomViewProgrammatically (Parent As Panel, Left As Int, Top As Int, Width As Int, Height As Int) As B4XComboBox
 Parent.LoadLayout("LayoutWithOnlyTheCustomViewMakeSureThatHandleResizeEventIsUnchecked")
 Dim v As View = Parent.GetView(Parent.NumberOfViews - 1)
 v.SetLayoutAnimated(0, 1, Left, Top, Width, Height)
 Return GlobalVariableWithTheSameNameAsTheNameOfTheViewInTheLayoutFileYouCreated
End Sub
 
Top