Android Question End Focus

CurtisC

Member
Licensed User
Longtime User
I have 2 arrays of edit texts and one single edit text. When I select any of the edit texts focus jumps to the next edit text, and focus remains active on the last edit text.

How can I

1) Exclude to single edit text from being focused from the edit test arrays?
2) End focus at the end of the arrays or when done with the single edit text.

I tried ForceDoneButton but Next remains. One option I found was closing the keyboard and setting focus to a edit text off screen. Is there a better way?
 

mc73

Well-Known Member
Licensed User
Longtime User
If I understand correctly, you should use the focusChanged event. Just an example:
B4X:
Sub Globals
   Dim txtSingle As EditText
   Dim txtArray(5) As EditText
   Dim arrExcludeTxts As String="1,3,":' exclude these textBoxes from getting focus upon 'next' pressed.
End Sub

Sub Activity_Create(FirstTime As Boolean)
   txtSingle.Initialize("txtSingle")
   txtSingle.SingleLine=True
   txtSingle.ForceDoneButton=True
   
   Activity.AddView(txtSingle,0,0,40%x,15%y)
   For i=0 To 4
     txtArray(i).Initialize("txtArray")
     txtArray(i).Tag=i
     txtArray(i).SingleLine=True
     Activity.AddView(txtArray(i),0,(i+1)*15%y,40%x,15%y)
   Next
   txtArray(4).ForceDoneButton=True
End Sub


Sub txtArray_FocusChanged (HasFocus As Boolean)
   Dim tempTxt As EditText=Sender
   Dim tempTag As Int=tempTxt.Tag
   If arrExcludeTxts.Contains(tempTag & ",") Then
     If tempTag<txtArray.Length-1 Then
       txtArray(tempTag+1).RequestFocus
     Else
       txtSingle.RequestFocus
     End If
   End If
End Sub
 
Upvote 0
Top