Display Panel on a CustomDialog

Inman

Well-Known Member
Licensed User
Longtime User
I have designed a B4A Panel with all the views like labels and buttons I need. I need this to be shown as a CustomDialog at the click of a button. The thing is when I try the CustomDialog.AddView I get an error that says I need to remove the Panel first before adding it. By removing the Panel, I loose all the design I did.

Is it possible to display a pre-designed Panel via CustomDialog library?
 

agraham

Expert
Licensed User
Longtime User
The Dialogs demo Sub btnCustom_Click populates a Panel programmatically and then adds it to a CustomDialog so there should also be no problem populating a Panel from a layout file.

I don't recognise the error, particularly as you have not quoted it verbatim, but I suspect a problem with your code. If you can't get it to work then post the actual code that fails.
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I followed your demo code and did my own. There was indeed some mistake on my part regarding initiliasing the control. Now I don't get any error but when the commondialog shows up, it is empty; it doesn't show my panel at all.

But I tried creating the panel and all the children programatically and it works fine. That solves it for the time being although in the future if I need to do some complex UI with panels, it will be tough to do it with code instead of the visual IDE.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Now I don't get any error but when the commondialog shows up, it is empty; it doesn't show my panel at all.
You must still be doing something wrong. You can see that using a layout does work by inserting one line in the demo code. It looks a mess of course but it's a crude way to show that it works.
B4X:
Sub btnCustom_Click
   Dim cd As CustomDialog
   Dim pnl As Panel
   pnl.Initialize("pnl")
   Dim bgnd As ColorDrawable
   bgnd.Initialize(Colors.Green, 5dip)
   pnl.Background = bgnd
   Dim btn1 As Button
   btn1.Initialize("btn1")
   btn1.Text = "Press me"
   pnl.AddView(btn1, 80dip, 50dip, 60dip, 60dip)
   lbl1.Initialize("")
   [COLOR="Red"]pnl.LoadLayout("layout") ' add this line[/COLOR]
   pnl.AddView(lbl1, 50dip, 120dip, 120dip, 60dip)
   cd.AddView(pnl, 5%x, 0%y, 77%x, 70%y) ' sizing relative to the screen size is probably best
   ret = cd.Show("B4A Custom Dialog", "Yes", "No", "Maybe", Bmp)      
End Sub
 
Upvote 0

Inman

Well-Known Member
Licensed User
Longtime User
I will test this code in my next project. I added everything programatically in my current one and I don't want to make any changes and upset the code. Thanks for the help mate.
 
Upvote 0
Top