Android Question BetterDialogs auto open/close Keyboard...

Discussion in 'Android Questions' started by wildfandango, Aug 20, 2019.

  1. wildfandango

    wildfandango Member Licensed User

    https://www.b4x.com/android/forum/t...hat-wont-keep-the-keyboard.63074/#post-398552

    Hi

    In my case I use

    Code:
    IP.Initialize
        IP.Question = msg
        IP.QuestionTextSize = 
    14
        IP.SpaceBetween = 
    4dip
        IP.InputTextSize = 
    20
        
    Select tip
            
    Case "c"
                IP.InputType = IP.INPUT_TYPE_TEXT
            
    Case "C"
                IP.InputType = IP.INPUT_TYPE_TEXT_WITH_CAPS
            
    Case "n"
                IP.InputType = IP.INPUT_TYPE_NUMBERS_WITH_SIGN
            
    Case "N"
                IP.InputType = IP.INPUT_TYPE_NUMBERS
            
    Case "d"
                IP.InputType = IP.INPUT_TYPE_DECIMAL_NUMBERS
            
    Case "D"
                IP.InputType = IP.INPUT_TYPE_DECIMAL_NUMBERS
            
    Case "t"
                IP.InputType = IP.INPUT_TYPE_PHONE
            
    Case "T"
                IP.InputType = IP.INPUT_TYPE_PHONE
        
    End Select
       
        IP.Gravity = 
    Gravity.CENTER_VERTICAL + Gravity.CENTER_HORIZONTAL
        
    'IP.ValidationCallback = "Input_Validation"
        IP.Hint=val
        
    'IP.Default=val
        IP.WithSuggestions = True

        RES = BD.InputBox(tit, IP, btn1, btn2, 
    ""Null)

            
    Dim r As Reflector
            r.Target = BD
            r.RunStaticMethod(
    "flm.b4a.betterdialogs.BetterDialogs""FermerClavierVirtuel"Array(r.GetActivityBA), Array As String("anywheresoftware.b4a.BA"))
    The keyboard does not open automatically, I must click in the text box to make the keyboard appear and when I exit (as you say) the keyboard remains open

    some advice? to take the focus and/or open/close the keyboard automatically.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

  3. wildfandango

    wildfandango Member Licensed User

    Thank you, Erel, I think I've already had a look at it, but I'll check it again carefully.

    my problem is that I have a series of windows-messages functions predefined in a code module, e.g. ask_number, ask_char etc.

    Which I then use in many parts of my application avoiding repeating many lines of code...

    If I try to do the same with XUI I get this message... STATIC CODE MODULES CANNOT HANDLE EVENTS

    Do you recommend me some way to do it? so I don't have to define ALL the function in each activity?

    thx in advance
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    Yes. Use classes.
     
  5. wildfandango

    wildfandango Member Licensed User

    I'm gonna try it!

    It hadn't occurred to me, I've been with B4A for years and had never used classes... :(

    I will upload here the advances because it is a fairly generic system of messages that could serve more people...

    In addition I would like to know your opinion to be the first class that I develop...

    Thank you
     
  6. wildfandango

    wildfandango Member Licensed User

    First Class Try

    Am I on the right track? ideas?

    Class Use
    Code:
    Dim getX As msgs
                    
    Dim r As Reflector

                    r.Target = r.GetActivityBA
                     
                    getX.Initialize(r.GetField(
    "vg") )
                    getX.askTEST(
    123.45,"TITLE","MESSAGE","YES","NO","CANCEL","n")
    Class Definition
    Code:
    ' Get valx msg class 
    Sub Class_Globals
       
        
    Private XUI As XUI
        
    Private Dialog As B4XDialog
        
    Private BView As B4XView
       
        
    Private title,message As String
        
    Private AllowDecimals, AllowNegative As Boolean
        
    Private lastBUT As Int                                    ' Last button pressed (XUI.DialogResponse_*)
        Private lastVAL As Object
       
        
    ' Maybe ?
        Private mainActivity As Activity
       
       
    End Sub






    Sub Initialize(maybe As Activity)
        mainActivity = maybe 
    '????
       
        BView = mainActivity
       
        Dialog.Initialize (BView)
    End Sub





    ' ask for a value, retur the value or null if cancel is pressed
    ' based on Input dialogs with XUI Views https://www.b4x.com/android/forum/threads/b4x-input-dialogs-with-xui-views.101197/
    ' title - message title
    ' format - message format
    ' msg - message

    ' btn1 - button 1 (text XUI.DialogResponse_Positive)
    ' btn2 - button 2 (text XUI.DialogResponse_Negative)
    ' btn3 - button 3 (text XUI.DialogResponse_Cancel)

    ' format - data format

    ' c - characters (lower and upper case)
    ' C - characters (upper case)
    ' n - int numbers (NOT AllowDecimals, AllowNegative) 
    ' N - int numbers (NOT AllowDecimals, NOT AllowNegative)
    ' d - dec numbers (AllowDecimals, AllowNegative) 
    ' D - dec numbers (AllowDecimals, NOT AllowNegative)
    ' p/P - phone number
    Sub askTEST(defaultValue As Object,tit As String,msg As String,btn1 As String, btn2 As String, btn3 As String, format As String)
        
    Dim input As B4XInputTemplate

        title = tit
        message = msg
        lastVAL = 
    Null
           
        
    Select format
            
    Case "c"                ' TODO c - characters (lower and upper case)
                AllowDecimals = False
                AllowNegative = 
    False
            
    Case "C"                ' TODO C - characters (upper case)
                AllowDecimals = False
                AllowNegative = 
    False
            
    Case "n"                ' n - int numbers (NOT AllowDecimals, AllowNegative)
                AllowDecimals = False
                AllowNegative = 
    True
            
    Case "N"                ' N - int numbers (NOT AllowDecimals, NOT AllowNegative)
                AllowDecimals = False
                AllowNegative = 
    False
            
    Case "d"                ' d - dec numbers (AllowDecimals, AllowNegative)
                AllowDecimals = True
                AllowNegative = 
    True
            
    Case "D"                ' D - dec numbers (AllowDecimals, NOT AllowNegative)
                AllowDecimals = True
                AllowNegative = 
    False
            
    Case "p","P"            ' TODO p/P - phone number
                AllowDecimals = False
                AllowNegative = 
    False
        
    End Select

        Dialog.Title = title
        Dialog.PutAtTop = 
    True
       
        input.Initialize
        input.lblTitle.Text = message
        input.Text = defaultValue
        input.ConfigureForNumbers(AllowDecimals, AllowNegative)

        
    Wait For (Dialog.ShowTemplate(input, btn1, btn2, btn3)) Complete (response As Int)
        lastBUT = response
       
        
    If lastBUT = XUI.DialogResponse_Positive Then
            lastVAL = input.Text
        
    End If
    End Sub

    Sub getVAL() As Object
        
    Return lastVAL
    End Sub

    ' TODO WHERE CALL ???? MainForm_Resize (Width As Double, Height As Double)
    Sub setSIZE (Width As Double, Height As Double)
        
    If Dialog.Visible Then Dialog.Resize(Width, Height)
    End Sub
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Why do you need this reflection code?

    Your code is much more complicated than it should be. You need to return a ResumableSub from askTEST.
     
  8. wildfandango

    wildfandango Member Licensed User

    Get automatically the current Activity

    Yes, I know that the class code is quite complex because I intend to simplify to the maximum the way to make the call, currently something of the style val = getX() and I intend that the new is as similar as possible so as not to have to rewrite all the code, in any case I will take a look at what you say ...

    https://www.b4x.com/android/forum/t...hat-return-values-resumablesub.82670/#content

    ResumableSubs are another concept that I have not worked with before.
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    The correct way is to pass the "parent":
    Code:
    Public Sub Initialize (Parent As B4XView)
    You can then pass an Activity in B4A, Page.RootPanel in B4i and Form.Pane in B4J.
     
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