iOS Question Keyboard TextView TextField

Yvon Steinthal

Active Member
Licensed User
Longtime User
Hello,

This is a recurring problem slowing constantly my app, probably because it is not meant to be done this way.

What im trying to do is do a simple scrollview scroll upon the selection of one of its many textboxes.

For this i've used a for each such as this:

B4X:
For Each v As View In pnlMainInfo.GetAllViewsRecursive
        
    If((v Is TextField And Not(Found)) ) Then
       Dim txtf As TextField = v
        
       If(txtf.IsFocused) Then
                Found = True
               KeyDifference = txtf.CalcRelativeKeyboardHeight(Height)
                        If(KeyDifference <0) Then
                        rx.sv.ScrollTo(0,-(KeyDifference-100),True)
                        End If
        End If
                
    Else if(v Is TextView And Not(Found)) Then       
        Dim txtv As TextView = v       
        
            If(txtv.IsFocused) Then
                Found = True
                KeyDifference = txtv.CalcRelativeKeyboardHeight(Height)
                        If(KeyDifference <0) Then
                        rx.sv.ScrollTo(0,-(KeyDifference-100),True)
                       End If
            End If
        
    End If
    Next
 
    If(Not(Found)) Then
    rx.sv.ScrollTo(0,0,True)
    End If

It works somewhat, however it is extremely slow on my ipad air recently bought. My question is as follows:

Is there a simple way to get the selected textbox without having to do such tedious loop? or at least the height?

Thank You!

Y.
 

Yvon Steinthal

Active Member
Licensed User
Longtime User
Yes exacly, scroll to the selected textfield, without having to go through a for each, especially since my panel in which i do my getallrecursiveviews has a lot of elements, slowing down my app at the same time. Any other way to do so? using the CalcKeyboardHeight trick isnt sufficient as im doing this on a scrollview...
 
Upvote 0

Yvon Steinthal

Active Member
Licensed User
Longtime User
I thought the KeyboardStateChanged method would arguably have a "Sender" pointing to the selected TextField or TextView, but it seems to end up being the entire Page...
 
Upvote 0

Yvon Steinthal

Active Member
Licensed User
Longtime User
Yes, but it wasn't exacly my problem...

However i just found a solution,

I added events for my textfields and textview (two different ones) that directly scroll to it without going to KeyboardStateChanged...
I didn't know about the BeginEdit event, it didn't help...

B4X:
Sub txt_v_BeginEdit
   
    Dim txtv As TextField
    txtv = Sender   
    sv.ScrollTo(0,txtv.top,True)

End Sub

Simple, but it works...

Y.
 
Upvote 0
Top