Android Question B4X SearchTemplate Dialog - Help Needed

skaliwag

Member
Licensed User
Longtime User
Couple of issues I hope someone can help with.

The dialog always starts with the IME keyboard displayed.
How can I change it so that the keyboard is not displayed until the search field is selected.

I am using SearchTemplate.Resize to make the dialog bigger.
This works, but stops the dialog from displaying the title.
Ideally, I would like the dialog to fill the screen but still display the title.

Many thanks
 

William Lancee

Well-Known Member
Licensed User
Longtime User
This wasn't that easy, and it isn't perfect but...
(To avoid problems with the keyboard pushing the ttile out the way, I had create my own title.)
I admit there could be better ways. It works.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    
    Private dia As B4XDialog
    Private srch As B4XSearchTemplate
    Private ime As IME
    Private titleBX As B4XView
End Sub

Public Sub Initialize
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    ime.Initialize("")
    dia.Initialize(Root)
    dia.TitleBarHeight = 0
    dia.BlurBackground = False
    dia.OverlayColor = xui.Color_Transparent
    srch.Initialize
    srch.SetItems(Array("AAA", "BBB", "CCC"))
    
    Dim title As Label
    title.Initialize("")
    titleBX = title
    titleBX.SetTextAlignment("CENTER", "CENTER")
    titleBX.Color = xui.Color_Blue
    titleBX.Font = xui.CreateDefaultBoldFont(20)
    titleBX.TextColor = xui.Color_White
    titleBX.Text = "This is the Title"
    titleBX.Visible = False
    Root.AddView(titleBX, 0, 0, Root.Width, 50dip)
End Sub


Private Sub Button1_Click
    Dim diaObject As Object = dia.ShowTemplate(srch, "", "", "")
    dia.Base.SetLayoutAnimated(0, 0, 50dip, Root.Width, Root.Height - 50dip)
    Sleep(25)
    ime.HideKeyboard
    titleBX.Visible = True
    srch.resize(Root.Width, Root.Height - 100dip)
    srch.SearchField.mBase.SetLayoutAnimated(0, 0, 0, Root.Width, 80dip)
    srch.SearchField.TextField.Width = Root.width
    srch.SearchField.lblClear.Left = Root.Width - 60dip
    srch.SearchField.lblV.Left = Root.Width - 30dip

    Wait For (diaObject) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Log(srch.SelectedItem)
    End If
End Sub
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
You know, since your goal is a full page, you could do this without using a popup like a dialog.
Use a CLV with a B4XFloatTextField and do your own search. You'll have full control.
 
Upvote 0

skaliwag

Member
Licensed User
Longtime User
Thank you.
This does indeed work as required.

Eventually, however, I decided to edit the searchtemplate.bal file instead and add the title there, as there were other bits and pieces that needed changing.

Then add some code to make the Back key behave as required (from elsewhere on the forum) :-
Make the Back key close the dialog:
'Back key on B4XDialog leaves the app by default
'Change it to close the dialog
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    If Dialog.Visible And  KeyCode = KeyCodes.KEYCODE_BACK And Dialog.Close(XUI.DialogResponse_Cancel) Then
        Return True
    Else
        Return False
    End If
End Sub

And resize the list depending on whether the keyboard is displayed, so we can still scroll to the bottom :-
Change list height when keyboard is displayed/hidden:
'Resize the list in the Load Dialog, so we can still scroll to the bottom
Sub IME_HeightChanged(NewHeight As Int, OldHeight As Int)
    If Dialog.Visible Then
        SearchTemplate.Resize(100%x,NewHeight)
    End If
End Sub
 
Last edited:
Upvote 0
Top