editBox

melamoud

Active Member
Licensed User
Longtime User
hi,

I'm using editBox focus change event to understand that the user finished entering the text , I have a list of edit boxes, and when the user moving from one to the other (in no predefined order, its what the user wants) I act on the value (save it to a file)

using the enter pressed event is not natural in my mind, people will move to the editBox they want and not going to press enter on the keyboard.

the only problem I have is that when user put data in the last field he might just press the back button exit the application in this case my app will go to pause activity and focus change event will never be thrown
is that a bug or an android behavior ?

anyone has a suggestion on how to solve it ?
 

Mahares

Expert
Licensed User
Longtime User
Did you already consider this: Intercept the back key press to prevent premature exit of the application. See below:
B4X:
Sub Activity_KeyPress(KeyCode As Int) As Boolean
    Dim Selection As Short
    If KeyCode = KeyCodes.KEYCODE_BACK Then    
       Selection = Msgbox2("Did you remember to save record. Exit application?".ToUpperCase, "C o n f i r m a t i o n", "Yes", "", "No", Null)       
       Select Selection   
              Case DialogResponse.POSITIVE              
                   Activity.Finish                   
              Case DialogResponse.CANCEL, DialogResponse.NEGATIVE 
                   Return True                      
       End Select   
    End If   
End Sub
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
Hi thanks.

Yea I thought about that what I need to do ig that happen is going over all editboxes or find the last one with focus get the text and save it.
I can do that the way you suggested or directly from pause activity sub.

I was looking for more elegant way that is part of the editbox event flow .
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
I don't quite get it. Why not looping through your editText boxes upon the 'back' key press and save data right there?
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
What I do currently is just that but from the pause activity not using the back key idea which is similar

Its just not an elegant way.
I would rather handle it as even if user leave app the component lose focus an even should have been thrown

Decouple the ui handling methods from the rest of the app is more elegant if I must stay with this approach I will.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
The lostFocus is triggered when something else receives focus, in Android and Windows. That's its meaning. When you hit a 'back' or 'exit' or 'minimize' (windows) there is no loss of focus.
Why not adding a 'save' button? After all, it's the user who should decide whether to save the bunch of data or abort them, under normal conditions.
 
Upvote 0

melamoud

Active Member
Licensed User
Longtime User
I can do that . Wanted to save the user from one more click.

I also nit getting the event when the user click a spinner (after the editbox) not sure why yet
Any idea?
 
Upvote 0

Similar Threads

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