User Controls kanaida

CharlesIPTI

Active Member
Licensed User
Longtime User
kanaida was trying something like this but I :sign0104: cant seem to get even a panel to appear atop another panel. Perhaps I shouldn't be using the designer scripts in the layout.. But

I appreciate any and all assistance thank you :sign0085:


Sub Activity_Create(FirstTime As Boolean)

panMain.Initialize("panMain")


Activity.AddView(panMain,0,0,0,0)

panMain.LoadLayout("layeredOne")
panSub.LoadLayout("layeredTwo")
Activity.AddView(panMain, 0%x, 0%x, 50%y ,50%x)

End Sub

I have a designer script in the horizontal 1280 x 800 layout variant. The Goal here is to just have several panels in the singular activity that I can Display , hide bring forward send back .. some of these panels will have to have "sub" panels in them to designate areas that will house additional views. This is an attempt to replicate a controller written in .NET where there were complex usercontrols all over this very overcrowded main form.

This specific test was an attempt at just TWO panels in the activity simultaneously displayed with both panels (equally divided ) in the activity housing views (panels) that contain more whoo hoo you guessed it panels.

I'm just trying one inside of one at this point but you get the idea. LayeredTwo layout also has a label just so i can see the difference.

Am I erroring because I haven't designated my sub panels as children of the panel that houses them? I'm presently being confronted with the error that I need to removeview() at line 43 when I call Activity.AddView(panMain, 0%x, 0%x, 50%y ,50%x) the specified child already has a parent. You must call removeView() on the child's parent first..
 

Attachments

  • layered.zip
    7.7 KB · Views: 156
Last edited:

kanaida

Active Member
Licensed User
Longtime User
I'm working on a code-generating designer in .net winforms... it's just easier to build a windows app to write all my b4a code for me lol... I'm spending 85% time on UI stuff, 15% on actual coding...

It's pretty simple:
a) I'm creating all the android view types in my Android namespace, each one inheriting the windows version of the equivalent control. like Spinner -> combobox

b) I'm making a form that you size the same as your target resolution, each type of view on the left like the Visual studio toolbox. Drag n drop em on the "Activity" which in my case is just a plain class inheriting form.

c) Create a .ToB4aCode() function on all my classes to make the code by reading the properties, but converting them to percentages so they scale ;) this might need tuning, but whatever. I'll figure that out later.

d) Save the View to an xml file to open and load user interfaces.

c) Iterate through the View and all it's child controls all the way down, calling MyView.ToB4aCode() > a text file etc... as i go along. overwrite whatever is in your activity code file done. That's the plan anyways. I automate stuff for a living so this is stuff I do at work all day long anyways...

e) I'd have the same code output for my own user controls output to panels, ready to tile. I'd have to make some subs to make that easier too since I can't do simple lambda expressions like: Newview.top = Panel.Children.Sum(function(x) x.height)

I appreciate the visual designer that comes with b4a and how cool it is to see your phone doing the same thing :), but me, I hate writing TONS of lines of code for stuff i'd normally just drag and drop and be done with it in one step.

This is a typical program for me so you can see where i'm coming from:
B4X:
        For Each p1 In OrdObj.Products
                    Dim objp1 = p1.Product
                    Dim available_p = (From x In Available Where x.Product.IsSameProductAs(objp1)
                                       Order By x.Warehouse,
                                       (Not x.StockType = StockType.SPI),
                                       (Not x.StockType = StockType.WEB)
                                       ).FirstOrDefault
                    If Not available_p Is Nothing Then
                        p1.Available.Add(available_p)
                        p1.AllocateProducts()
                    End If
                Next


By the way, Erel if you see this... is there command-line commands we can use to use b4a as a compiler for apk's if we make our own code b4a editor/generator to avoid some copy/pasting?
 
Last edited:
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
As for your panel problem...
The sub-panel in your case is inside the main panel, (think buckets inside buckets). You should add them both to a parent panel (siblings, not parent-child) or activity first or one will be inside the other.
I know it's a bit funny, but make the left property=100%w on the panel when you want to hide it. :) load em both up, then hide one, just mess with the left position value and see it that helps :). Perhaps there's a visible property that might work too, can't remember.

I usually do stuff like this:

Activity
|
Panel1
|-View1
|-View2
|
Panel2
|-SomeOtherViews


Also: The AHPager library is pretty awesome, although at first it was a little confusing for me, but allows swyping panels left to right to switch between them.

Things are a bit easier when you start to see it's more like asp.net, except with only modules and no classes.
.bal / layout files are like the designer view
and the code, is like the code behind.

Activity_Create is like: Page_Load
and whenever you turn your device around, its the equivalent of hitting refresh on your browser. This confused me at first, thought i'd be more like winforms.
 
Last edited:
Upvote 0

CharlesIPTI

Active Member
Licensed User
Longtime User
Confirmation

Ponder the applicability this scenario if you'd be so kind..

Master Panel added Programmatically to Activity & lets use Names to protect the innocent or maintain sanity whichever is more appropriate..

MasterPanelUsercontrolAlpha = mpUcAlpha OK? shorter name

Activity.AddView(mpUcAlpha,0%x, 0%x, 50%y ,50%x)

#1) DO I have to initialize this panel first before Attempting to add it?

#2) Can I do my next bit of kraziness - the next panel (loPanel_SubAlphaContentForMaster) in a layout and with a designer script and load the layout into the Master panel mpUcAlpha?

mpUcAlpha.LoadLayout(loPanel_SubAlphaContentForMaster)


Then somewhere in the app when its time to replace this mpUcAlpha with
some new functionality so I need to make mpUcAlpha disappear and bring in mpUcBeta.... do same thing wash rinse repeat....? Or do I maintain mpUcAlpha and just loadlayout a different subset which actually represents a different usercontrol again created as a layout with a designer script to help with the placement of the views ?

Lastly in these layouts, there is a panel which service as a base..(BasePanel) for accurate placement in the activity.. then another panel in it (Control Grouper) and potentially multiple panels in that one (UserControls) ,,,, which finally hold groups of views. You suggested I make this latter grouped set (UserControls) as children of the (BasePanel) panel in the hierarchy instead of children of the activity or children of (Control Grouper) ??






I like your idea however of automating the control layout by doing it in an external app and exporting the settings.
 
Last edited:
Upvote 0

kanaida

Active Member
Licensed User
Longtime User
I've attached a project sample with some comments. You'll see it's not that hard, it's just stuff that normally vb.net would write for you automatically so we're not used to it.

In this example I have 2 panels that you can switch between using a spinner/combobox at the bottom.
each panel has different colors and content so you can see there's no parlor tricks :)
 
Upvote 0
Top