0 Replies Latest reply on Nov 11, 2011 9:02 AM by Formability.co.uk

    softKeyboard affecting click event on Android

    Formability.co.uk

      I am using Flex 4.5.1 with a trial version of Flash Builder 4.5.

       

      In one of views (login screen) I have a form that is attached to the center of the screen and when the keyboard appears (when you click into the inputs) all is fine. However if I try to click the submit button (which has an event handler on it) the event doesn't fire, and only the keyboard disappears. I then have to click the button a second time to get the click event to fire. This issue does not happen on the ipad I'm testing with.

       

      If the form is attached to the top of the screen and therefore doesn't get moved when the keyboard appears then everything works as expected, it only seems to happen when the button is moved by the keyboard appearing. I assumed that I needed to remove and re-add the event listener but that had no impact.

       

      I then worked on a sample application that worked with keyboard events and created the same situation in that which I've included below. I originally had the event listener defined directly in the mxml but changed it to the below as a test.

       

      What can I do to get the click event to fire on the login button without having to click on it twice?

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                     xmlns:s="library://ns.adobe.com/flex/spark"
                     creationComplete="init_app(event)">
          <fx:Script>
              <![CDATA[
                  
                  import flash.events.StatusEvent;
                  import flash.net.SharedObject;
                  import flash.net.URLRequest;
                  import flash.net.registerClassAlias;
                  
                  import mx.events.FlexEvent;
                  import mx.rpc.events.ResultEvent;
                  
                  import spark.events.TextOperationEvent;
                  
                  [Bindable]
                  private var state:String;
                  
                  [Bindable]
                  private var type:String;
                  
                  private function handleActivating(event:SoftKeyboardEvent):void {
                      state = "Activating...";
                      type = event.triggerType;
                      busy.visible = true;
                  }
                  
                  private function handleActivate(event:SoftKeyboardEvent):void {
                      login_but.removeEventListener(MouseEvent.CLICK, login_but_clickHandler);
                      login_but.addEventListener(MouseEvent.CLICK, login_but_clickHandler);
                      if (login_but.willTrigger('click')) state = "Active1";
                      else state = "Active2";
                      type = event.triggerType;
                      busy.visible = false;
                  }
                  
                  private function handleDeactivate(event:SoftKeyboardEvent):void {
                      login_but.removeEventListener(MouseEvent.CLICK, login_but_clickHandler);
                      login_but.addEventListener(MouseEvent.CLICK, login_but_clickHandler);
                      if (login_but.willTrigger('click')) state = "Deactive1";
                      else state = "Deactive2";
                      type = event.triggerType;
                  }
                  
                  protected function login_but_clickHandler(event:MouseEvent):void
                  {
                      busy.visible = true;
                  }
                  
                  protected function show_keyboard_clickHandler(event:MouseEvent):void
                  {
                      busy.visible = true;
                  }
                  
                  protected function password_changeHandler(event:TextOperationEvent):void
                  {
                      if(password.text.length > 0)
                          login_but.enabled = true;
                      else
                          login_but.enabled = false;
                  }
                  
                  protected function init_app(event:FlexEvent):void
                  {
                      login_but.addEventListener(MouseEvent.CLICK, login_but_clickHandler);
                  }
                  
                  
              ]]>
          </fx:Script>
          <s:VGroup left="20" bottom="40" right="20" gap="15"
                    softKeyboardActivating="handleActivating(event)"
                    softKeyboardActivate="handleActivate(event)"
                    softKeyboardDeactivate="handleDeactivate(event)">
              <s:HGroup>
                  <s:Label text="Keyboard State: " fontWeight="bold"/>
                  <s:Label text="{state}"/>
              </s:HGroup>
              <s:HGroup>
                  <s:Label text="Trigger Type: " fontWeight="bold"/>
                  <s:Label text="{type}"/>
              </s:HGroup>
              <s:TextInput id="username" width="301" prompt="Enter username..." />
              <s:TextInput id="password" width="301" displayAsPassword="true" prompt="Enter password..." change="password_changeHandler(event)" />
              <s:HGroup width="100%" gap="15">
                  <s:Button label="Cancel" click="show_keyboard_clickHandler(event)" width="50%"/>
              </s:HGroup>
              <s:Button id="login_but" width="123" label="Log In" />
              <s:BusyIndicator id="busy" visible="false" width="66" height="66" />
          </s:VGroup>
      </s:Application>