Android Question Moving to another EditText

johnaaronrose

Active Member
Licensed User
Longtime User
I have 2 EditText views. I enter alphabetic text in the first one (whose Name & Tag is edtOSGBGridRef1) which is validated (by Sub edtOSGBGridRef1Valid i.e. Returns True) as OK. I now want to move to the other whose Name & Tag is edtOSGBGridRef2 (which requires numerics on its keyboard). However, the code shown below results in moving to another View - a button. I know that the Case of "edtOSGBGridRef1" is being executed due to a Log in the edtOSGBGridRef1 routine being displayed. I've removed the line "IME.HideKeyboard" with no success. I feel that it's something to do with the line "IME.ShowKeyboard(edtOSGBGridRef2)" being in this Sub. However, it doesn't seem correct to put it into the Sub edtOSGBGridRef1_FocusChanged where the test HasFocus = False is True.

B4X:
    Sub IME_HandleAction As Boolean
    Dim edt As EditText
    edt = Sender
    Log("IME_HandleAction:")
    Log("EditText.Tag="&edt.Tag)
    Select edt.Tag
    Case "edtOSGBGridRef1"
        If edtOSGBGridRef1Valid Then
            IME.HideKeyboard
            IME.ShowKeyboard(edtOSGBGridRef2)
        Else
            ToastMessageShow("Correct OSGB Grid Reference Map", True)
            'Consume the event
            'The keyboard will not be closed
            Return True
        End If
 

johnaaronrose

Active Member
Licensed User
Longtime User
Why don't you call edtOSGBGridRef2.RequestFocus instead of hiding and showing the keyboard?

When I try that, it works OK but it does not work in the HandleAction sub for when the value edtOSGBGridRef2 is being entered: it goes to a another view. I brought this up on another thread and someone suggested that I use the Accessibility library on
http://www.b4x.com/android/forum/threads/requestfocus-does-not-work.37334/#post-220095
using SetFocus... commands but that gave problems. So I abandoned that.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
I've now abandoned the use of HandleAction as that gives problems with doing validation i.e. validation works OK when using Enter (i.e. Next) key but not if the next view is pressed without using Enter. I now know that the SetRequestFocus does not work for a button (btnOSGBGridRef) when I want to proceed to it from the last EditText view's (edtOSGBGridRef3) EnterPressed Sub as the value assigned to btnOSGBGridRef.SetRequestFocus is False: shown by a ToastMessage.
 
Upvote 0

johnaaronrose

Active Member
Licensed User
Longtime User
I've now abandoned the use of HandleAction as that gives problems with doing validation i.e. validation works OK when using Enter (i.e. Next) key but not if the next view is pressed without using Enter. I now know that the SetRequestFocus does not work for a button (btnOSGBGridRef) when I want to proceed to it from the last EditText view's (edtOSGBGridRef3) EnterPressed Sub as the value assigned to btnOSGBGridRef.SetRequestFocus is False: shown by a ToastMessage.
I've now reinstituted HandleAction as covered in thread http://www.b4x.com/android/forum/threads/class-edittext-field-order.28002/page-2
That thread also shows how to make RequestFocus work OK for a button.
 
Upvote 0
Top