Skip to first unread message

Leonard Jowers

unread,
Jun 27, 2014, 2:02:19 AM6/27/14
to mitappinv...@googlegroups.com
My application is simple. Key into a text box (color change on focus), press a command button. When I press the command button, ".LostFocus" does not occur (color change on lost focus). What have I missed?

Enis

unread,
Jun 27, 2014, 8:50:21 AM6/27/14
to mitappinv...@googlegroups.com
Easy way would be to change the text box's color when the button is pressed.

Greg Jensen

unread,
Jun 27, 2014, 1:24:45 PM6/27/14
to mitappinv...@googlegroups.com
In general with AI2 you can't programmatically trigger component events like .LostFocus or .Click etc. The only exception I've found is with sliders. When you set the ThumbPosition property of a slider it automatically triggers the slider's PositionChanged event.  As Enis suggested just set the colour change to your button's .Click event.  If you have code you need to attach to multiple component events, put in in a procedure and call the procedure from each event. 

Also Text boxes hold the focus until you touch another text box. Thus the HideKeyboard method.  

Leonard Jowers

unread,
Jun 27, 2014, 6:54:57 PM6/27/14
to mitappinv...@googlegroups.com
I had tried that, among other things. See attachments. Is there something I did wrong?
DesignerView.png
BlocksView.png

Enis

unread,
Jun 27, 2014, 6:56:55 PM6/27/14
to
Leonard...

What's the point of this thread?  EVERYTHING you're doing there closes the screen!  Why do you care about a control's focus?

In addition, you cannot close Screen1 without "Close Application"

Leonard Jowers

unread,
Jun 27, 2014, 9:32:17 PM6/27/14
to mitappinv...@googlegroups.com
I used close screen because I could not find any other token to close the control. What did I miss?

Enis

unread,
Jun 28, 2014, 12:02:51 AM6/28/14
to mitappinv...@googlegroups.com
What control are you trying to close?  Close screen "ain't" it...

You can make things visible and invisible.  Are these controls in arrangements?  If so, make the whole arrangement invisible or visible. All you've asked about is setting focus.
  1. On Screen1, close screen is worthless.  You cannot close screen1.  You can close the application but not screen1.
  2. What exactly do you want to do.  Your code doesn't exactly explain what you're trying to do.  What ARE you trying to do?
  3. What's the point in setting a picture property just to hide the component?  If you're going to hide the thing, why set the picture in the first place??
  4. Have you done the tutorials?  If not, I suggest you do.  The tutorials are located here: http://appinventor.mit.edu/explore/ai2/tutorials


Greg Jensen

unread,
Jun 28, 2014, 12:28:53 AM6/28/14
to mitappinv...@googlegroups.com
You cannot 'unfocus' or make a textbox loose focus unless another textbox is receiving the focus.  All you can do is the HideKeyboard method. Where do you need the focus to go? You don't have anyplace to accept focus.
As Enis asked.. what is your purpose?  What function are you trying to provide?  Ask yourself these questions and rethink it for the tools. 

Leonard Jowers

unread,
Jun 28, 2014, 11:59:03 AM6/28/14
to mitappinv...@googlegroups.com
Thanks. I thought that clicking the button would change focus to the button.

Leonard Jowers

unread,
Jun 29, 2014, 12:32:08 AM6/29/14
to mitappinv...@googlegroups.com
For future readers, the only way I could get the unfocus I wanted was to have another visible text box and manually tap it.

 

Better Ways of Learning

unread,
Feb 17, 2015, 3:19:48 AM2/17/15
to mitappinv...@googlegroups.com
I'm having the same problem.

The reason it's important to lose focus, is stuff is triggered after they lose focus.

I have users enter:
-Min number (text box 1)
-Max number (text bos 2)

Then after, they press a button to start an activity.

The problem is if they change anything in text box 1 or 2, and immediately click on the button then the values don't update because the lost focus event never occurred.

Enis

unread,
Feb 17, 2015, 8:08:52 AM2/17/15
to mitappinv...@googlegroups.com
The way to LOSE focus is to SET FOCUS to something else.  The newest release (140) allows you to RequestFocus to a text box...

Better Ways of Learning

unread,
Feb 18, 2015, 2:08:50 AM2/18/15
to mitappinv...@googlegroups.com
Since my functionality is all in the "lose focus" blocks for each textbox, for the button's code I had it request focus to both textboxes (thus each one would lose focus once) and then the code would run in those blocks before the main action of the button press.

MartynC

unread,
Feb 18, 2015, 3:23:58 AM2/18/15
to mitappinv...@googlegroups.com
I had a similar problem. I ended up changing the text boxes to buttons and then using a notifier for the text input; on button click, activate a notifier.ShowTextDialogue. Then use a notifier.AfterTextInput to capture the user input.
To allow for multiple buttons, on button click, I set a global variable to tell me which button was pressed and then check the variable in the AfterTextInput function.
Not an ideal solution, it means you have a popup when entering data but it works for me.


artist RewCa

unread,
Mar 15, 2015, 10:45:54 AM3/15/15
to mitappinv...@googlegroups.com
As an FYI, In trying to do input validation after data input, I had two text fields in focus.  Both blinking...

When I touched another field, it got Focus.  But when the error routine checked the previous field, I set focus to it again.  Thus, both had focus. 

I need to really redesign how I validate input data.... Not one field at a time...
Reply all
Reply to author
Forward
0 new messages