A question with a ScrollView

JoanRPM

Active Member
Licensed User
Longtime User
Hi all.

In an application, I use a ScrollView to edit text. Some text is not editable using the keyboard (in the date format, I opens a calendar). When I return to the activity of the list (after selecting a date), selecting a cell, the keyboard no longer works as before.

Example: Suppose a long ScrollView we want to select a cell in the bottom of the screen. By clicking, you open the keyboard and the cell rises to the top of the keyboard (since it would remain hidden).
This works well unless we pressed a date cell format before. In this case the cell is hidden behind the keyboard.

In the attached example the sequence would be:
- Click on "Name 5". The keyboard appears and cell 5 above the keyboard.
- Exit the keyboard and click on "Name 0". This opens a MessageBox ( simulating the calendar).
- Press "OK" to return to the main activity.
- Click on "Name 5". Now the cell "Name 5" appears behind the keyboard !!

I do not know how to fix it.

Many thanks in advance.
 

Attachments

  • TestScroll.zip
    6.3 KB · Views: 288
Last edited:

Roger Garstang

Well-Known Member
Licensed User
Longtime User
Add IME Library and the lines in Globals, Create, and Resume along with the IME function at the end to your code:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.

   Dim scvFicha As ScrollView
   Dim Edit1(6) As EditText
   Dim btnOk  As Button
   Dim IME As IME
   
   Dim pntype As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
   
   IME.Initialize("IME")
   IME.AddHeightChangedEvent
   scvFicha.Initialize(500)
   Activity.AddView(scvFicha,0,0,100%x,85%y)
   FillScvFicha

End Sub

Sub Activity_Resume
   scvFicha.Height = Activity.Height
End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub FillScvFicha
   Dim Panel0 As Panel
   Dim PanelTop, PanelHeight, Label2Top As Int
   
   Dim s() As String
   
   PanelTop=0
   Panel0=scvFicha.Panel
   Panel0.Color=Colors.Gray

   For i=0 To Edit1.Length - 1
      Dim Panel1 As Panel
      
       Panel1.Initialize("")
      Panel1.Tag=i
      PanelHeight=70dip
      Panel0.AddView(Panel1,0,PanelTop,scvFicha.Width,PanelHeight)
      Panel1.Color=Colors.Black
      
      Dim Label1 As Label
      Label1.Initialize("lblView")
      Panel1.AddView(Label1,10dip,10dip,90%x,50dip)
      Label1.TextSize=16
      Label1.Gravity=Gravity.CENTER_VERTICAL
      Label1.Color=Colors.Black
      Label1.Tag=i
      Label1.Text="Text "&i

      Edit1(i).Initialize("edtView")
      Panel1.AddView(Edit1(i),25%x,10dip,100%x-25%x-5dip,50dip)
      Edit1(i).TextSize=20
      Edit1(i).Gravity=Gravity.CENTER_VERTICAL
      Edit1(i).SingleLine = True
      Edit1(i).ForceDoneButton = True
      Edit1(i).Wrap = True
      Edit1(i).Tag=i
      Edit1(i).Text = "Name"&i

      PanelTop=PanelTop+PanelHeight+1dip
   Next
   Panel0.Height=PanelTop
End Sub

Sub edtView_FocusChanged (HasFocus As Boolean)
   Dim edt As EditText
   Dim row As Int
   edt = Sender
   
   row = edt.Tag

   If HasFocus = True Then
      If row = 0 Then StartActivity(Aux1)
   End If
End Sub

Sub edtView_Click
   Dim edt As EditText
   Dim row As Int
   edt = Sender
   
   row = edt.Tag

End Sub

Sub btnOk_Click
   pntype.RemoveView
End Sub

Sub IME_HeightChanged (NewHeight As Int, OldHeight As Int)
   scvFicha.Height = NewHeight
End Sub
 
Upvote 0

JoanRPM

Active Member
Licensed User
Longtime User
Hi.

Once tested this on my application, I notice that does not work very well.
My ScrollView is not until the end of the screen. It is from 0 to 85%y. But now (with the IME library) the ScrollView reaches to the end.
In my final version, there are some buttons at the bottom of the screen that now are overwritten.
I tried to do several convinations with the EMI library, but not working.

In this example I added a simple button at the bottom of the screen. The button is above the ScrollView (the ScrollView Height should be a little smaller).

Thank you.
 

Attachments

  • TestScroll2.zip
    6.6 KB · Views: 287
Upvote 0

Roger Garstang

Well-Known Member
Licensed User
Longtime User
You will need to adjust for any differences in Activity_Resume and IME_HeightChanged. The code in Activity_Resume is used because sometimes when you navigate to another Activity or messagebox with the keyboard opened it will return back to your original activity without firing the returning IME_HeightChanged that should fire when the keyboard closes, so Resume would always set the size to 85%y in your case to restore the height correctly in that case (Also eliminates any need for sizing the scrollview in Create other than the Initialize).

IME_HeightChanged you will probably need some logic like seeing if the new height is larger than the old (Should mean keyboard is closed/bigger screen) then set height to 85%y in that case and scvFicha.Height = NewHeight if it is smaller. Should be a simple If/Then/Else.

To not look funny you may want to shift your buttons up and down with the scrollview too...although they probably won't show since not on the scrollview they won't be scrolling visible. You could also include them in the calculation and make the scrollview size the new height - button height and move the buttons up so they are visible.
 
Last edited:
Upvote 0

JoanRPM

Active Member
Licensed User
Longtime User
Roger.
Now it seems it works right.
What I have done is to memorize in a global variable, the value of the height of the ScrollView. Then in IME_HeightChanged and in Activity_Resume we recover the stored data.
The code is not very elegant, but it works.
I let the code in case anyone is also interested.

Thanks for your advice.
 

Attachments

  • TestScroll2.zip
    6.6 KB · Views: 295
Last edited:
Upvote 0
Top