Custom Dialog 2 (issue getting to work)

wheretheidivides

Active Member
Licensed User
Longtime User
I am trying to set up a custom dialog box 2, but the instructions are vague. I set up a layout and am trying to use the layout in the CD2

I get this error at the point it loads the custom dialog 2 (not when the main layout is loaded):
"Warning: Panel.LoadLayout called with zero sized panel."
===============================
Also, I am trying to load and unload variables. The 3 lables are supposed to be loaded and display variables. They don't. I think it is how I'm trying to do to do this. They show "-" in the picture which is the default and not the variable. The variables do have info in them.

I have never understood initialize. I thought things were inited when the layout is loaded, but if I do not init, it gives and error. I have no ideal of what goes inside the ().

You can see in picture that it doesn't even set the radio buttons. none are set when the popup occurs.

This is probably a simple solution. Thanks in advance.

===============================


B4X:
'-----------------------------------------
            Dim CustPanel1 As Panel
            Dim CD1Time, CD1Table, CD1Type As Label
            Dim CD1ETTime, CD1ETTable As EditText
            Dim CD1TypeC, CD1TypeT, CD1Type1, CD1TypeX As RadioButton
            
         '---------------------------------
            CustPanel1.Initialize(1)
            
            CD1Time.Initialize(1)
            CD1Table.Initialize(1)
            CD1Type.Initialize(1)
            
            CD1ETTime.Initialize(1)
            CD1ETTable.Initialize(1)
            
            CD1TypeC.Initialize(1)
            CD1TypeT.Initialize(1)
            CD1Type1.Initialize(1)
            CD1TypeX.Initialize(1)
            
            DoEvents

         '----------------------------------
            Cd2.AddView(CustPanel1, 320, 300) 'width, height
            
         '-------------------------------------
            CustPanel1.LoadLayout("layoutcd1.bal")
            
         '-------------------------------------
            CD1Time.Text = ST1200amA
            CD1Table.Text = ST1200amB
            CD1Type.Text = ST1200amC
            
            Log("---------------------------------")
            Log("Time: " & CD1Time.Text & "-" & ST1200amA)
            Log("Table: " & CD1Table.Text & "-" & ST1200amB)
            Log("Type: " & CD1Type.Text & "-" & ST1200amC)
            Log("---------------------------------")
            
         '----------------------------------------
            If ST1200amC = "Cash" Then
               CD1TypeC.Checked = True
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
              Else If ST1200amC = "Tourn" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = True
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
            Else If ST1200amC = "Sit/Go" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = True
               CD1TypeX.Checked = False
               
            Else If ST1200amC = "Free" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = True
               
            Else
               'default in case the text is not right
               CD1TypeC.Checked = True
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
            End If
         
         '----------------------------------
            RetModify = Cd2.Show("Changes all 3 fields:" & CRLF & "Time, Table & Type.", "Change", "Cancel", "", Bmp_Chips15)
         -
 

Attachments

  • a.jpg
    a.jpg
    62.6 KB · Views: 246
Last edited:

thedesolatesoul

Expert
Licensed User
Longtime User
I am not sure, but to avoid the error you are getting you need to add the panel first to something, and then load the layout.
So these lines order is changed:
B4X:
Cd2.AddView(CustPanel1, 320, 300) 'width, height
CustPanel1.LoadLayout("layoutcd1.bal")
Again I am not sure, but this is what I gather from the warning you posted: Warning: Panel.LoadLayout called with zero sized panel
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
Yep, that fixed the layout error. Thanks.

Now, why doesn't the variables load and display properly? The 3 variables have info in them, but do not display. 1 variable time, 1 variable table and 1 variable type for the radio button. The radio button has none checked when loaded yet there is a if-then loop setting one of them.

These are the variables going into the labels

B4X:
CD1Time.Text = ST1200amA
   CD1Table.Text = ST1200amB
   CD1Type.Text = ST1200amC
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
Are there radiobuttons part of the layout? (CD1Time, CD1Table, CD1Type)
If they are part of the layout then you must *not* initialise them.

The simple rule for initialise is that when the views are part of the layout you do not initialise them, otherwise if you create them in code, then you have to initialise them.
Inside the () for Initialize goes the eventname.
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
If I don't init them then when I click to open up the dialog box it gives and error must be inited. I thought if they were part of the layout you don't init them.
"java.lang.RuntimeException: Object should first be initialized (Label)."

and what does this mean?
"Inside the () for Initialize goes the eventname."

(CD1Time, CD1Table, CD1Type)
These are labels on the layout. In fact, all of these are on the layout

Dim CD1Time, CD1Table, CD1Type As Label
Dim CD1ETTime, CD1ETTable As EditText
Dim CD1TypeC, CD1TypeT, CD1Type1, CD1TypeX As RadioButton
 
Last edited:
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
Why are you initializing them if they are part of the layout?
Focus on what the error is trying to say. It cant find the label that you declared in code on the layout.
If you are unsure use the Generate Members option in the designer to generate the Dim statements in code.

If I knew why, I wouldn't have started a new thread (so im a suckey programmer.). The labels are dimed right there. Using generate members does the same thing but makes them global. The error says init them, so I do. If I don't, then it crashes. There must be something in the code not allow me to set the text of the labels and set the radio buttons. I'm sure it is something real simple.

at this point
'----------------------------------------
If ST1200amC = "Cash" Then
CD1TypeC.Checked = True
CD1TypeT.Checked = False
CD1Type1.Checked = False
CD1TypeX.Checked = False

'=======================
both of these vars are = Cash
CD1Type.Text
ST1200amC

so why doesn't it set the CD1TypeC to true and display on when the dialog box pops up?

(forget time and table, they have nothing in them. Type has 'Cash' for both. This is the log just betfore setting the radio buttons (all that materrs is cash and cash)
Time: -
Table: -
Type: Cash-Cash
---------------------------------
 
Last edited:
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
Bal file
simple as it is.

I had them in panels but took them out as they were not working,
 

Attachments

  • layoutcd1.bal
    6 KB · Views: 179
Last edited:
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
It's not obvious from the code you have posted, but have you Dimmed the items in Sub Globals?

No, not in sub globals. Right there in the subroutine.

B4X:
Sub Button7011_Click
'1200am ST DB
'-----------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK/Databases/dbStringTr.dat") = True Then
      '-----------------------------------------
      If db.Record_Count < 1 Then
         ToastMessageShow("There are no string tracker records.", True)
         
      Else If db.Record_Count >= 1 Then
         '-----------------------------------------
            Dim CustPanel1 As Panel
            Dim CD1Time, CD1Table, CD1Type As Label
            Dim CD1ETTime, CD1ETTable As EditText
            Dim CD1TypeC, CD1TypeT, CD1Type1, CD1TypeX As RadioButton            
         '---------------------------------
            CustPanel1.Initialize(1)
            
            CD1Time.Initialize(1)
            CD1Table.Initialize(1)
            CD1Type.Initialize(1)
            
            CD1ETTime.Initialize(1)
            CD1ETTable.Initialize(1)
            
            CD1TypeC.Initialize(1)
            CD1TypeT.Initialize(1)
            CD1Type1.Initialize(1)
            CD1TypeX.Initialize(1)
            
            DoEvents
         '----------------------------------
            Cd2.AddView(CustPanel1, 320, 300) 'width, height            
         '-------------------------------------
            CustPanel1.LoadLayout("layoutcd1.bal")            
         '-------------------------------------
            CD1Time.Text = ST1200amA
            CD1Table.Text = ST1200amB
            CD1Type.Text = ST1200amC
            
            Log("---------------------------------")
            Log("Time: " & CD1Time.Text & "-" & ST1200amA)
            Log("Table: " & CD1Table.Text & "-" & ST1200amB)
            Log("Type: " & CD1Type.Text & "-" & ST1200amC)
            Log("---------------------------------")
            
         '----------------------------------------
            If ST1200amC = "Cash" Then
               CD1TypeC.Checked = True
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
              Else If ST1200amC = "Tourn" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = True
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
            Else If ST1200amC = "Sit/Go" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = True
               CD1TypeX.Checked = False
               
            Else If ST1200amC = "Free" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = True
               
            Else
               'default in case the text is not right
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = True
               
            End If
         
         '----------------------------------
            RetModify = Cd2.Show("Changes all 3 fields:" & CRLF & "Time, Table & Type.", "Change", "Cancel", "", Bmp_Chips15)
         
         '--------------------------------------
            Select RetModify
               Case DialogResponse.POSITIVE
                  '--------------------------------
                  ST1200amA = CD1ETTime.Text
                     db.PutField("DB2_ST1200amA", ST1200amA) 'WA2
                     LabelST1200amA.Text = ST1200amA
                  '--------------------------------
                  ST1200amB = CD1ETTable.text
                     db.PutField("DB2_ST1200amB", ST1200amB) 'WA2
                     LabelST1200amB.Text = ST1200amB
                  '--------------------------------
                  '--------------------------------
                  If CD1TypeC.Checked = True Then
                     ST1200amC = "Cash"
                     
                     db.PutField("DB2_ST1200amC", ST1200amC) 'WA2
                     LabelST1200amC.Text = ST1200amC
                  '--------------------------------
                  Else If CD1TypeT.Checked = True Then
                     ST1200amC = "Tourn"
                     
                     db.PutField("DB2_ST1200amC", ST1200amC) 'WA2
                     LabelST1200amC.Text = ST1200amC
                  '--------------------------------
                  Else If CD1Type1.Checked = True Then
                     ST1200amC = "Sit/Go" 
                     
                     db.PutField("DB2_ST1200amC", ST1200amC) 'WA2
                     LabelST1200amC.Text = ST1200amC
                  '--------------------------------
                  Else If CD1TypeX.Checked = True Then
                     ST1200amC = "Free"
                     
                     db.PutField("DB2_ST1200amC", ST1200amC) 'WA2
                     LabelST1200amC.Text = ST1200amC
                     
                  End If
                  '--------------------------------
                  db.UpdateRecord
                  Msgbox("Record(s) were changed." & CRLF & "Time: " & LabelST1200amC & CRLF & "Table: " & LabelST1200amC & CRLF & "Type: " & LabelST1200amC, "")                                    
                  Label7000Record.Text = (db.Record_Pointer +1) & " of " & db.Record_Count
                  
                  '--------------------------------
               Case DialogResponse.CANCEL
                  Msgbox("Canceled.  Record(s) were not changed.", "")
               
               Case DialogResponse.NEGATIVE
                  'nothing
                  
            End Select
            '-----------------------------------------
      End If

   Else
      ToastMessageShow("There is no 'String Tracker' database.", True)   
   End If
   
'-----------------------------------------
End Sub
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
They need to be in sub globals, then remove the initializations, if they are all in the layout file.
 
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
It works fine for me.

This is the code I used.
Also note that white text on a white background, you will be able to see NOTHING.

I get no errors with Initialize ( Object should first be initialized (Label)).
I did get ImageView errors because I didnt have the file, so I deleted the file property.

B4X:
Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim CD1Table As Label
   Dim CD1Time As Label
   Dim CD1Type As Label
   'Dim CD1Time, CD1Table, CD1Type As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("layoutcd1")
   CD1Table.TextColor = Colors.Black
   CD1Table.Text = "Hello2"

   CD1Time.TextColor = Colors.Black 
   CD1Time.Text = "HelloTime"
End Sub
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
BINGO! we have a weiner, winner. Sorry.

The problem was that the variables needed to be globals. Here's the working code for the next person who has this issue. and thanks for the help.

B4X:
Sub Globals
'Custon DIalog2 7011
   Dim CustPanel1 As Panel
   Dim CD1Time, CD1Table, CD1Type As Label
   Dim CD1ETTime, CD1ETTable As EditText
   Dim CD1TypeC, CD1TypeT, CD1Type1, CD1TypeX As RadioButton

B4X:
Sub Button7011_Click
'1200am ST DB
'-----------------------------------------
   If File.Exists(File.DirRootExternal, "/Saved/PDTK/Databases/dbStringTr.dat") = True Then
      '-----------------------------------------
      If db.Record_Count < 1 Then
         ToastMessageShow("There are no string tracker records.", True)
         
      Else If db.Record_Count >= 1 Then
         '-----------------------------------------
            CustPanel1.Initialize(1)
            
            DoEvents
         '----------------------------------
            Cd2.AddView(CustPanel1, 320, 300) 'width, height            
         '-------------------------------------
            CustPanel1.LoadLayout("layoutcd1.bal")            
         '-------------------------------------
            CD1Time.Text = ST1200amA
            CD1Table.Text = ST1200amB
            CD1Type.Text = ST1200amC
            
            Log("---------------------------------")
            Log("Time: " & CD1Time.Text & "-" & ST1200amA)
            Log("Table: " & CD1Table.Text & "-" & ST1200amB)
            Log("Type: " & CD1Type.Text & "-" & ST1200amC)
            Log("---------------------------------")
            
         '----------------------------------------
            If ST1200amC = "Cash" Then
               CD1TypeC.Checked = True
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
              Else If ST1200amC = "Tourn" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = True
               CD1Type1.Checked = False
               CD1TypeX.Checked = False
               
            Else If ST1200amC = "Sit/Go" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = True
               CD1TypeX.Checked = False
               
            Else If ST1200amC = "Free" Then
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = True
               
            Else
               'default in case the text is not right
               CD1TypeC.Checked = False
               CD1TypeT.Checked = False
               CD1Type1.Checked = False
               CD1TypeX.Checked = True
               
            End If
         
         '----------------------------------
            RetModify = Cd2.Show("Changes all 3 fields:" & CRLF & "Time, Table & Type.", "Change", "Cancel", "", Bmp_Chips15)
         
         '--------------------------------------
            Select RetModify
               Case DialogResponse.POSITIVE
 
Upvote 0
Top