B4J Tutorial Modal dialogs

Discussion in 'B4J Tutorials' started by Erel, Nov 19, 2013.

  1. Erel

    Erel Administrator Staff Member Licensed User

    B4J allows you to show modal dialogs or modal forms.
    The difference between a modal form to non-modal form is that with a modal form the calling code will only continue after the form is closed.

    Showing a modal form is done by calling Form.ShowAndWait.

    For example to create a very simple color picker:
    [​IMG]

    Code:
    Sub btnColor_Action
       
    Dim mf As ModalForm
       mf.Initialize(MainForm)
       MainForm.BackColor = mf.Show
    End Sub
    ModalForm is a class. Internally it calls Form.ShowAndWait.

    Code:
    Public Sub Show As Paint
       frm.ShowAndWait
       
    'The next line will only be executed after the form is closed.
       Return colorsMap.Get(lstColors.SelectedItem)
    End Sub
    Msgbox library is available here: Msgbox library
     

    Attached Files:

    Last edited: Dec 3, 2013
  2. RobRock92

    RobRock92 Member Licensed User

    how do to create two forms connected by a button?
     
    rayzrocket likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    What do you mean with "connected by a button"? (please start a new thread for this question)
     
  4. Shadow&Max

    Shadow&Max Active Member Licensed User

    Erel... Anyway to do this in Basic4Android??? I don't understand how to a) create the forms, and b) to link it into b4a. I'd like to make a small, modal dialog that pops up with a panel containing 2 labels, 2 sliders, and 3 buttons down below... Want to pop that up modal, allow settings, and then dismiss the panel.

    I've searched and I came up with this B4J example, but am pretty sure I can't use it! Any suggestions would be appreciated... Thnx in advance...
     
  5. derez

    derez Expert Licensed User

  6. Shadow&Max

    Shadow&Max Active Member Licensed User

    Thank you... None of them suit my needs... I was able to do it by disabling controls underneath while my panel was visible, and re-enable everything after it goes away.
     
  7. derez

    derez Expert Licensed User

    Instead of enabling and disabling, you can put the dialog on a panel covering the whole screen (transparent or opaque or partial) and consume any touch by this panel.
     
  8. Shadow&Max

    Shadow&Max Active Member Licensed User

    See, I didn't want to cover the entire screen... I wanted it to look like a pop-up dialog box. I was able to do it very cleanly...
     
  9. FrenchDeveloper

    FrenchDeveloper Member Licensed User

    Hello Derez,
    In B4j, how to allow clicks on underlaying applications when the transparent panel is topmost ?
     
  10. derez

    derez Expert Licensed User

    You have to disable the panel .
     
  11. jonydoboi

    jonydoboi Member Licensed User

    Another example based on the first one. The return type is String instead of Paint.
    It took a while to figure out.
     

    Attached Files:

    Last edited: Jul 25, 2014
    tdocs2 likes this.
  12. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Erel, for your continued support.

    Your competence is only exceeded by your perseverance - I do hope you find a couple of clones....

    The example in post 1 does not work in Win 10. Since I do not know how to modify FXML (there is no Form in the Views), I created a form in Open Designer. The only way it works is by setting the form backcolor to Transparent.

    I tried to improve the app (Ha! - presumptuous of me), and I got stuck :oops:

    I got this far:
    Code:
    For i = 0 To colorsMap.Size -1
            
    Dim lblx As TextField
            lblx.Initialize(
    "")
            lblx.Text=colorsMap.GetKeyAt(i)
            lblx.Style=
    "-fx-text-fill: " & colorsMap.GetKeyAt(i) & ";"
            
    Log(lblx.Text)
            lstColors.Items.Add(lblx)
        
    Next
    which shows each item in the Listview in the matching color.

    Since I am adding a label, I DO NOT KNOW HOW TO RETRIEVE ITS TEXT VALUE AND "CLICK" DOES NOT WORK ON CLICKING THE LABEL.
    How do I do this?

    Thank you.

    Sandy
     
  13. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    I al not at my pc so i am not so sure about the answer but if you are passing the textfield to the listview you can retrieve the information not with a click of the textfield but with the event on selection changed of the listview

    Dim tf as textfield = listview.get( listview.selectedindex)

    Something like that.
     
    tdocs2 likes this.
  14. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Enrique.

    Code:
    Dim tf As TextField = lstColors.Items.get(lstColors.selectedindex)
        
    Log(tf.text)
        
    Return fx.Colors ??????????
    It is as above. Now that I have the name of the color in tf.text, how do I return the corresponding fx.colors?

    Sandy
     
  15. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    I hope it is like this

    Return Mapcolors.getkeyat(lstColors.Items.get(lstColors.selectedindex)

    You will return the specified index of the colorsmap. Well I hope as soon as I am at my computer I will try it too. I
     
    tdocs2 likes this.
  16. tdocs2

    tdocs2 Well-Known Member Licensed User

    Close - Thank you, Enrique - you put me on the right track. This is the code:

    Code:
    Public Sub Show As Paint
        frm.ShowAndWait
        
    Dim tf As TextField = lstColors.Items.get(lstColors.selectedindex)
        
    Return colorsMap.Get(tf.text)
    End Sub
    Best wishes.

    Sandy

    PS: How can I capture a click on the label itself? Got to get some sleep....
     
  17. Enrique Gonzalez R

    Enrique Gonzalez R Well-Known Member Licensed User

    for a label within a listview:

    Code:
    sub listview_selectedindexchanged(index as int)
         
    dim l as label 
         
    label = listview.items.get(index)
         
    log(label.text)
    end sub
     
    tdocs2 likes this.
  18. tdocs2

    tdocs2 Well-Known Member Licensed User

    Thank you, Enrique.

    The sub works, but it does not capture the mouse click on the label. I have to click outside of the label....

    Best wishes.

    Sandy
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice