Android Question Keep Keyboard from hiding after entering

JamesGreaves

Active Member
Licensed User
I would like the keyboard to show, after pressing Enter, and the entry does not meet the criteria.
I've tried everything I can think of, but in vain.
Any ideas?

B4X:
Sub EditText1_EnterPressed
    
    If EditText1.Text <> "something" Then
        
        EditText1.RequestFocus
        IME.ShowKeyboard(EditText1)
        Return
        
    End If
       
End Sub

Sub EditText1_TextChanged (Old As String, New As String)
    IME.ShowKeyboard(EditText1)
End Sub

Sub EditText1_FocusChanged (HasFocus As Boolean)
    IME.ShowKeyboard(EditText1)
End Sub
 

JamesGreaves

Active Member
Licensed User
Let me perhaps rephrase the problem.
1. If you click on an EditText view, the Keyboard appears.
2. Once you click Done/Enter, the keyboard hides itself away.
3. I want the text entered into the EditText, to be then evaluated and if it doesn't meet the requirements then: the EditText view should regain Focus and the Keyboard must show itself again.
It seams so simple, yet I'm finding it impossible to achieve.
Any ideas?

upload_2019-1-25_16-18-8.png
 

JamesGreaves

Active Member
Licensed User
I've made a simple app to demonstrate my problem.
So basically I want the keyboard to show again after <Done> is clicked.
I would appreciate any help on this.
Thank you.

upload_2019-1-25_17-51-42.png



B4X:
Sub Globals
    Private EditText1 As EditText
     Dim IME As IME
    Private butShowKeyboard As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("Main")
    IME.Initialize("")
    EditText1.SelectAll
End Sub

Sub EditText1_EnterPressed
    
    If EditText1.Text <> "something" Then
        
        IME.ShowKeyboard(EditText1)
        EditText1.RequestFocus
        EditText1.SelectAll
        
        Return
        
    End If
    
    butShowKeyboard.RequestFocus
    
End Sub

Sub EditText1_TextChanged (Old As String, New As String)
    
End Sub

Sub EditText1_FocusChanged (HasFocus As Boolean)
    IME.ShowKeyboard(EditText1)
End Sub
 
Sub butShowKeyboard_Click
    EditText1.RequestFocus
    IME.ShowKeyboard(EditText1)
End Sub
 

Attachments

mc73

Well-Known Member
Licensed User
Have a look at the attached project, and the source here. We use the handleAction event of the IME object, which we attach to editText1. Just for verifying it works OK, I've added another editText, with no input restriction.

B4X:
Sub Globals
   Private EditText1 As EditText:'we set ime_handleAction to check this view
     Private EditText2 As EditText:'we set nothing here
   Dim IME As IME
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   IME.Initialize("IME")
   IME.AddHandleActionEvent(EditText1)
End Sub

Sub IME_HandleAction As Boolean
   Dim e As EditText
   e = Sender
   If e=EditText1 Then
       If e.Text<> "something" Then
           ToastMessageShow($""something" not entered"$,True)
           EditText1.SelectAll
           Return True
       Else
           Return False 'will close the keyboard
       End If
   Else
       Return False
   End If  
End Sub
 

Attachments

JamesGreaves

Active Member
Licensed User
Brilliant, brilliant!!!
That is perfect, exactly what I needed. I was beginning to think it was impossible.
Thank you VERY much!!
 
Top