Android Question xCustomListView the Keyboard hides B4XFloatTextField

angel_

Well-Known Member
Licensed User
Longtime User
I use B4XPages where I load a Layout with a xCustomListView, to this xClv I load a panel (as B4XView) with differents views, including B4XFloatTextField when I select those that are lower than the keyboard hides the view, there is some way to avoid it?
 

Mahares

Expert
Licensed User
Longtime User
there is some way to avoid it?
Post #8 in the below thread gets you started with the IME_HeightChanged event :
Then you use the IME_HeightChanged event for the panel holding the child views like the B4XTextField and others in any B4XPage. If you get stuck, come back with your code and layout. Somebody will help.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Here is some code from a project of mine very much as @Mahares describes. I use a scrollview but the principle is the same. The scrollview is fullpage so when the IME keyboard opens I move the bottom of the scrollview up. Each EditText is on a panel, and you need to use the FocusChanged event of the text box to find out which panel is the target. Then you scroll the scrollview so that the target panel is visible.

It is much simpler than it sounds. Here is the code ...

B4X:
Sub Globals

' ...   

    Dim inputPanelPos As Int       ' Bottom of focussed text panel
    Dim workHeight As Int = 0        ' Current keyboard height

' ...
End Sub
    

' Calculate position of base of currently focussed text panel
Private Sub text_FocusChanged (HasFocus As Boolean)
    Dim v As EditText = Sender
    Dim p As Panel = v.Parent
    If HasFocus Then inputPanelPos = p.top + p.Height
    If (workHeight > 0) Then scrBase.ScrollPosition = inputPanelPos - workHeight
End Sub

Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
    If (NewHeight < OldHeight) Then    ' Keyboard is open
        workHeight = NewHeight
        scrBase.SetLayout(0, 0, Activity.Width, NewHeight)
        scrBase.ScrollPosition = inputPanelPos - NewHeight
    Else
        scrBase.SetLayout(0, 0, Activity.Width, Activity.Height)
        workHeight = 0                  ' Keyboard closed
    End If   
End Sub
 
Upvote 0

labsklinik

New Member
Here is some code from a project of mine very much as @Mahares describes. I use a scrollview but the principle is the same. The scrollview is fullpage so when the IME keyboard opens I move the bottom of the scrollview up. Each EditText is on a panel, and you need to use the FocusChanged event of the text box to find out which panel is the target. Then you scroll the scrollview so that the target panel is visible.

It is much simpler than it sounds. Here is the code ...

B4X:
Sub Globals

' ...  

    Dim inputPanelPos As Int       ' Bottom of focussed text panel
    Dim workHeight As Int = 0        ' Current keyboard height

' ...
End Sub
   

' Calculate position of base of currently focussed text panel
Private Sub text_FocusChanged (HasFocus As Boolean)
    Dim v As EditText = Sender
    Dim p As Panel = v.Parent
    If HasFocus Then inputPanelPos = p.top + p.Height
    If (workHeight > 0) Then scrBase.ScrollPosition = inputPanelPos - workHeight
End Sub

Private Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
    If (NewHeight < OldHeight) Then    ' Keyboard is open
        workHeight = NewHeight
        scrBase.SetLayout(0, 0, Activity.Width, NewHeight)
        scrBase.ScrollPosition = inputPanelPos - NewHeight
    Else
        scrBase.SetLayout(0, 0, Activity.Width, Activity.Height)
        workHeight = 0                  ' Keyboard closed
    End If  
End Sub
hi Brian..
i try that code, but what is scrBase ?
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
i try that code, but what is scrBase ?
I am not sure which project that was, but in my naming system "scr" usually identifies a scrollView. If you look at the first paragraph of post #3 you will see that I use a scrollview to carry all of the input panels (which in turn carry the editText boxes) to make it easier to move the whole layout up to make room for the IME keyboard. It is necessary to track focus changes to recognise which is the most recently focussed input.

When the keyboard opens the bottom of the scrollview is moved up to align with the top of the keyboard. "workheight" is set to the remaining available screen height. If the most recently focussed edit box of now under the keyboard (maybe only partially) the panel is scrolled up so that it is in full view.
 
Upvote 0

labsklinik

New Member
Saya tidak yakin proyek mana yang dimaksud, tetapi dalam sistem penamaan saya, "scr" biasanya mengidentifikasi scrollView. Jika Anda melihat paragraf pertama dari posting #3, Anda akan melihat bahwa saya menggunakan scrollview untuk membawa semua panel input (yang pada gilirannya membawa kotak editText) agar lebih mudah untuk memindahkan seluruh tata letak ke atas guna memberi ruang bagi papan ketik IME. Penting untuk melacak perubahan fokus guna mengenali input mana yang paling baru difokuskan.

Saat keyboard terbuka, bagian bawah scrollview digeser ke atas agar sejajar dengan bagian atas keyboard. "workheight" diatur ke tinggi layar yang tersisa. Jika kotak edit yang terakhir difokuskan sekarang berada di bawah keyboard (mungkin hanya sebagian), panel digulir ke atas sehingga terlihat penuh.
Thank you Brian.. I will try..
 
Upvote 0
Top