Android Question BetterDialogs auto open/close Keyboard...

wildfandango

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

If the virtual keyboard is opened with the OpenKeyboard property of BetterDialogs, then it is properly closed when the dialog is closed. BUT it cannot be closed if you open it by clicking on the EditText because BetterDialogs does not know that a virtual keyboard is opened. It's not related at all to the modality of the dialog. Run the following code after CustomDialog and the virtual keyboard will close:
B4X:
Dim r As Reflector
r.Target = BD
r.RunStaticMethod("flm.b4a.betterdialogs.BetterDialogs", "FermerClavierVirtuel", Array(r.GetActivityBA), Array As String("anywheresoftware.b4a.BA"))

Hi

In my case I use

B4X:
    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.
 

wildfandango

Member
Licensed User
Longtime 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
 

Attachments

  • Sin título.png
    Sin título.png
    49.4 KB · Views: 304
Upvote 0

wildfandango

Member
Licensed User
Longtime 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
 
Upvote 0

wildfandango

Member
Licensed User
Longtime User
First Class Try

Am I on the right track? ideas?

Class Use
B4X:
                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
B4X:
' 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
 
Upvote 0

wildfandango

Member
Licensed User
Longtime User
Why do you need this reflection code?

Get automatically the current Activity

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

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.
 
Upvote 0
Top