Android Question Audio feedback from keyboard in a EditText

JamesGreaves

Active Member
Licensed User
I am wanting to get Audio feedback from text entered into a EditText view.

I thought of getting the last key pressed and play the associated audio file, but I cannot find how to get the last key pressed.

B4X:
Sub txtNewReading_TextChanged (Old As String, New As String
    MP.Load(File.DirAssets, KeyPressed & ".mp3"):   
    MP.Play
End Sub

Any ideas?
I already have all the Audio files, i.e. "1.mp3", "2.mp3", "3.mp3", etc...
 

JamesGreaves

Active Member
Licensed User
OK, I found a way by comparing the OLD and NEW text.
Not sure it is the best way, but it works.
I am still open to know the correct/proper or the best way.

B4X:
Sub txtNewReading_TextChanged (Old As String, New As String)


    If New.Length > Old.Length Then
        Old = Old & "!"
        For i = 0 To Old.Length-1
        
            If Old.SubString2(i,i+1) <> New.SubString2(i,i+1) Then
              
                Dim KeyPressed As String = New.SubString2(i,i+1)
                MP.Load(File.DirAssets, KeyPressed & ".mp3"): MP.Play

                Exit
              
            End If
        Next
                
    Else
        MP.Load(File.DirAssets, "Delete.mp3"): MP.Play
        
    End If

End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…