Android Question Enterpressed for any EditText [Solved]

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All,

I have an activity with several EditTexts, I have a sub that is actioned whenever the Enterpressed event occurs on any of the EditTexts.
Instead of writing a Sub to handle each editText is there a way to detect Enterpressed on any EditText.

Regards Roger

IE:
B4X:
'Instead of:
Sub Edt1_EnterPressed
    Action
End Sub

Sub Edt2_EnterPressed
    Action
End Sub

Sub Edt3_EnterPressed
    Action
End Sub  
Etc. Etc. Etc......

'could possibly be:
Sub AnyOldEdt_EnterPressed
    Action
End Sub
 
Last edited:

drgottjr

Well-Known Member
Licensed User
Longtime User
didn't i explain this to you in a different thread yesterday? you use the tag property to identify which edittext the user was in when she pressed the enter key...
 
Upvote 0

mangojack

Well-Known Member
Licensed User
Longtime User
Possible solution ...
1. set the tag property of all edittexts .. ie: edt1, edt2
2. set all EditText event names to a common event. ie: EditText

B4X:
Sub EditText_EnterPressed
    Dim edt As EditText = Sender

    Select edt.Tag
        Case "edt1"
            Log ("yipy")
        Case "edt2"
            Log("zipy")
    End Select
End Sub


Edit ... Apologies @drgottjr ... I thought you might be confusing this with OPs question regarding EditText Focus Today but maybe not.
 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
didn't i explain this to you in a different thread yesterday? you use the tag property to identify which edittext the user was in when she pressed the enter key...


No drgottjr, you answered a different question regarding edittexts and focus.

 
Upvote 0

Roger Daley

Well-Known Member
Licensed User
Longtime User
Possible solution ...
1. set the tag property of all edittexts .. ie: edt1, edt2
2. set all EditText event names to a common event. ie: EditText

B4X:
Sub EditText_EnterPressed
    Dim edt As EditText = Sender

    Select edt.Tag
        Case "edt1"
            Log ("yipy")
        Case "edt2"
            Log("zipy")
    End Select
End Sub


Edit ... Apologies @drgottjr ... I thought you might be confusing this with OPs question regarding EditText Focus Today but maybe not.


Thanks mangojack,
I must have been having a bad day, I have used this technique in the past to handle keys on a keyboard and of course it works well.

Regards Roger
 
Upvote 0

drgottjr

Well-Known Member
Licensed User
Longtime User
i believe my answer from that link said, among other things:
if you only have 1 edittext view, then you don't need:
B4X:

Dim editer As EditText
editer = Sender

this part. (and, of course, you wouldn't need to reference the tag property. if you have multiple edittext views and you wanted to know which one had the focus, you would populate the tag property and then refer to it in the enter_press and/or focus_changed subs.
 
Upvote 0
Top