Custom Dialog Question

wheretheidivides

Active Member
Licensed User
Longtime User
Sorry about all of the messages lately but I'm nearing the finish of an app.

I wanted to make a custom dialog with radio buttons. Here's my code which crashes. Again, no info in the instructions, but did find some partial code. It's probably something real simple as always. It gives a nullpointerexpection error on the line

RetModify = Cd2.Show("Change Category", "Save", "Cancel", "", Bmp)


code deleted and modified version shown at later message
 
Last edited:

wheretheidivides

Active Member
Licensed User
Longtime User
If anyone has a demo code of a custom dialog box, please post or put link here. I have no idea of how to make one, but if I see code, I can figure it out. I really would like to see example of a custom dialog box with 3 radio buttons and how to get which one was pressed.
 
Upvote 0

wheretheidivides

Active Member
Licensed User
Longtime User
That helped. I am now able to get up a radio box custom dialog box with 3 inputs as shown below and there text. I get it. You add buttons, radio, labels to a panel. Then you show the panel. Then you can also change the properties of the elements. got it.

1 last question, what does initialize do?

CustPanel.Initialize("pnl")
CustRadioA.Initialize(1)
CustRadioB.Initialize(2
and here
Dim bgnd As ColorDrawable

bgnd.Initialize(Colors.DarkGray, 5dip)
CustPanel.Background = bgnd


B4X:
Sub ButtonTest2_Click
'-------------------------------
   Dim CustPanel As Panel
   Dim CustRadioA, CustRadioB As RadioButton
'---------------------------------
   CustPanel.Initialize("pnl")
       CustRadioA.Initialize(1)
       CustRadioB.Initialize(2)

   CustRadioA.Text = "Have Receipt"
   CustRadioB.Text = "No Receipt"
   
   DoEvents
'-------------------------------------
   Dim bgnd As ColorDrawable
    
   bgnd.Initialize(Colors.Cyan, 5dip)
    CustPanel.Background = bgnd
'---------------------------------------
   'Dim CustButtonA, CustButtonB As Button
   
   CustPanel.AddView(CustRadioA, 0, 10, 400, 50)
      CustPanel.AddView(CustRadioB, 0, 60, 400, 50)
      
   Cd2.AddView(CustPanel, 400, 170)
'----------------------------------------
   CustRadioA.Checked = True
     CustRadioB.Checked = False
'----------------------------------
   RetModify = Cd2.Show("Have Receipt?", "Save", "Cancel", "", Bmp)
'--------------------------------------
'-1 positive, -3 cancel
   Select RetModify
      Case DialogResponse.POSITIVE
         Msgbox("Saved.  Field was modified.","")
      
      Case DialogResponse.CANCEL
         Msgbox("Canceled.  Field was NOT modified.","")
      
      Case DialogResponse.NEGATIVE
         'nothing
         
   End Select
'--------------------------------
   If CustRadioA.Checked=True Then
      Msgbox("'Have Receipt' selected.","")
   
   Else If CustRadioB.Checked=True Then
      Msgbox("'No Receipt' selected.","")
   
   Else
      Msgbox("None selected?  WTF?","")
   End If
      
'--------------------------------
End Sub
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1 last question, what does initialize do?

CustPanel.Initialize("pnl")
CustRadioA.Initialize(1)
CustRadioB.Initialize(2)

In the case of views, Initialize creates the native view. The EventName parameter sets the subs that will handle the events.

If you set the EventName to pnl then you can create the following subs:
pnl_Click
pnl_LongClick
...

Setting it to 1 or 2 is the same as passing an empty string. No events will fire.
 
Upvote 0
Top