I have a CLV and each row has a label as view(0) and an edittext as view(1)
When I use the following code to change focus from one edittext in one row to the edittext in the next row I get the error in the image setSpan(1 ... 1) ends beyond length 0
How do I fix this please
B4X:
currentcut = currentcut + 1
Dim pa As Panel = clvSideA.GetPanel(currentcut)
pa.GetView(1).RequestFocus
I'm using SD Custom keyboard and suspect it might be too do with that.
When a button is pressed on the custom keyboard it enters the text into the edittext. The text changed event fires and this is where I set focus to the next exittext.
Try this, I hope I understood what you wanted to do.
Private Sub ETCutA_TextChanged (Old As String, New As String):
Private Sub ETCutA_TextChanged (Old As String, New As String)
Dim ETCutAView As Object = Sender
If ETCutAView Is EditText Then
Dim position2 As Int = clv.GetItemFromView(ETCutAView)
If position2 < clv.Size - 1 Then 'So that it does not crash when it is in the last EditText
Dim nextPanel As Panel = clv.GetPanel(position2 + 1)
Dim nextEditText As EditText = nextPanel.GetView(1)
Sleep(10) 'this prevents the following error -> java.lang.IndexOutOfBoundsException: setSpan
nextEditText.RequestFocus
End If
End If
End Sub
Private Sub ETCutA_TextChanged (Old As String, New As String)
Log("ETCutA Text Changed Position = " & position)
If flagTextChanged = False Then 'global flag
flagTextChanged = True
Return
End If
position = position+1
If position < clv.Size Then
Dim pa As Panel = clv.GetPanel(position)
Sleep(0) 'required
pa.GetView(1).RequestFocus
flagTextChanged = False
End If
End Sub
Hey guys much smarter than me thanks for your help so far but could I trouble you a little further.
At the moment I have it so that you click the keyboard the text is entered and it moves onto the next field selecting all text if any so pressing the keyboard replaces all existing text.
This is exactly what I want
I need help so that when a user manually selects another edittex it automatically selects all text but can't figure it out.
I had a play with the example ... Unfortunately I could not resolve your issue & I am now out of time (back to work for me ..)
A couple of observations though.
B4X:
Private Sub ETCuta_FocusChanged (HasFocus As Boolean)
Also the code never executes past testing the view as an EditText , (which ETCutA is )
B4X:
Private Sub ETCutA_FocusChanged (HasFocus As Boolean)
If HasFocus = True Then
Dim ETCutAView As Object = Sender
If ETCutAView Is EditText Then 'commenting this line test results in the following error
'java.lang.ClassCastException: b4a.example.sd_keyboard cannot be cast to android.view.View
Dim position2 As Int = clv.GetItemFromView(ETCutAView)
Dim nextPanel As Panel = clv.GetPanel(position2)
Dim nextEditText As EditText = nextPanel.GetView(1)
Sleep(10) 'this prevents the following error -> java.lang.IndexOutOfBoundsException: setSpan
nextEditText.SelectAll
End If
End If
End Sub
Without having any knowledge working with the SD Custom Keyboard , again I cannot help you with this one.
I also tried it for a long time, I managed to get all the text to be selected when I clicked it but the rest stopped working.
I don't understand why when using the custom keyboard in the TextChanged event, sender returns null
I have tried putting a transparent panel over the edittext and when clicked it returns the panel but my code still will not select all text.
I don't actually want the user to type into the edittext but replace it with what's on the keyboard when pressed.
Trapping the panel touch does not seem to work either.
I have tried putting a transparent panel over the edittext and when clicked it returns the panel but my code still will not select all text.
I don't actually want the user to type into the edittext but replace it with what's on the keyboard when pressed.
Trapping the panel touch does not seem to work either.
Private Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
Dim pan As Object = Sender
If pan Is Panel Then
Dim position2 As Int = clv.GetItemFromView(pan)
Dim panItem As Panel = clv.GetPanel(position2)
Dim txtETCutA As EditText = panItem.GetView(1)
Sleep(10) 'this prevents the following error -> java.lang.IndexOutOfBoundsException: setSpan
txtETCutA.SelectAll
txtETCutA.RequestFocus
End If
End Sub
Private Sub Panel1_Touch (Action As Int, X As Float, Y As Float)
Dim pan As Object = Sender
If pan Is Panel Then
Dim position2 As Int = clv.GetItemFromView(pan)
Dim panItem As Panel = clv.GetPanel(position2)
Dim txtETCutA As EditText = panItem.GetView(1)
Sleep(10) 'this prevents the following error -> java.lang.IndexOutOfBoundsException: setSpan
txtETCutA.SelectAll
txtETCutA.RequestFocus
End If
End Sub
I had an issue with this in B4i. I have my own onscreen keyboard and it turns out ios won't select text unless the keyboard is visible.
So I gave up trying to highlight and just replace the text.