Android Code Snippet Non-centered Custom layout dialog

Discussion in 'Code Snippets' started by Erel, Oct 26, 2017.

  1. Erel

    Erel Administrator Staff Member Licensed User


    This example uses JavaObject to change the CustomLayoutDialog position.
    It also demonstrates how to access the layout fields and how to make sure that the keyboard is closed when the dialog is dismissed.

    The layout file looks like this:


    Note that EditText1 is the first view and EditText2 is the second view. You can change the order of views by dragging them in the views tree.

    Sub Activity_Click
    Dim dialog As CustomLayoutDialog
    Dim sf As Object = dialog.ShowAsync("""Yes""Cancel""No"NullFalse)
    'Code to change top position
       Dim jo As JavaObject = sf
    Dim window As JavaObject = jo.RunMethodJO("getWindow"Null)
    Dim lp As JavaObject = window.RunMethod("getAttributes"Null)
    "gravity"Bit.Or(Gravity.TOP, Gravity.CENTER_HORIZONTAL))
    "y"40dip'set the top position
       Wait For (sf) Dialog_Ready (DialogPanel As Panel)
    Dim firstName As EditText = DialogPanel.GetView(0)
    Dim lastname As EditText = DialogPanel.GetView(1)
    Wait For (sf) Dialog_Result (Result As Int)
       firstName.Enabled = 
    False 'disable the text fields to make the keyboard disappear
       lastname.Enabled = False
    If Result = DialogResponse.POSITIVE Then
    Log("First name: " & firstName.Text)
    Log("Last name: " & lastname.Text)
    End If
    End Sub
    Depends on the latest version of Dialogs library.
  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