Android Question Event For EditText

Sreenadh OG

Member
Licensed User
Longtime User
Hi,
I have a Layout contain a Edittext, I want to get EnterPressed event for edittext and i want to use it multiple times...My code is.
B4X:
Sub txAddItem_EnterPressed
    Try
'    If HasFocus =True Then
        'Calculation.GetListItem
        Dim cur As Cursor
        Dim getItem As String
        Dim list_add As List
        Dim listId As Int
        list_add.Initialize
        cur=Calculation.Sqlcnn.ExecQuery("Select reason from tbl_reason")
        For i=0 To cur.RowCount-1
            cur.Position=i
            list_add.Add(cur.GetString("reason"))
        Next 
        listId=InputList(list_add,"Select An Item",1)
        getItem=list_add.get(listId)
        txAddItem.Text =getItem
'    End If
Catch
End Try 
End Sub
 
Last edited:

Sreenadh OG

Member
Licensed User
Longtime User
I want to use the EnterPressed event multiple times without unloading the layout,
for each entering I want to perform some action..
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Ok.

For each EditText you have to use the same EventName.
The Calling EditText object should be accessible over the Sender object. So your event sub should look like this:

(created from mind so there may be errors)

B4X:
Sub <YourCommonEventNameForAllEditTexts>_EnterPressed
   Dim et as EditText
   et = Sender

    Try
'    If HasFocus =True Then
        'Calculation.GetListItem
        Dim cur As Cursor
        Dim getItem As String
        Dim list_add As List
        Dim listId As Int
        list_add.Initialize
        cur=Calculation.Sqlcnn.ExecQuery("Select reason from tbl_reason")
        For i=0 To cur.RowCount-1
            cur.Position=i
            list_add.Add(cur.GetString("reason"))
        Next
        listId=InputList(list_add,"Select An Item",1)
        getItem=list_add.get(listId)
        et.Text =getItem
'    End If
Catch
End Try
End Sub
 
Upvote 0

Sreenadh OG

Member
Licensed User
Longtime User
But I have only one editText, I am showing Listview in EnterPressed event of editText,
(now i want remove focus from edittext)
This is my screenshot..
clickeventnew.JPG

First time I am enter the EditText it work successfully, but second entering "sub txt_ EnterPressed " didn't work
 
Last edited:
Upvote 0

corwin42

Expert
Licensed User
Longtime User
The event should fire whenever enter is pressed. Maybe there is another error which is catched by the try/catch block. Try to remove it or create at least some log output when an exception is caught.
 
Upvote 0
Top