2 Replies Latest reply on Dec 12, 2011 11:53 AM by thiagollo

    TextInput in List

    thiagollo

      Hello,

       

      I have a list with textInput on my mobile project (flex 4.6). But seems to be a crazy behavior on list.

      When i set the value on textInput i take the event normally, but when i scroll the list the value appear on others text input... see the images and the code below:

       

      1. List with textInput:

      foto1.png

       

      2. The code for that (iconItemRenderer):

       

      <?xml version="1.0" encoding="utf-8"?>

      <componentes:IconItemRendererCustomizado xmlns:fx="http://ns.adobe.com/mxml/2009"

                          xmlns:s="library://ns.adobe.com/flex/spark" 

                          xmlns:componentes="componentes.*"

                          labelField="nomeFormatado" messageField="mensagem"

                          fontSize="24" messageStyleName="myFontStyle"

                          iconHeight="72" iconWidth="72"

                          dataChange="iconitemrenderercustomizado1_dataChangeHandler(event)"

                          initialize="iconitemrenderercustomizado1_initializeHandler(event)">

          <fx:Script>

              <![CDATA[

                  import mx.events.FlexEvent;

                 

                  import spark.components.Application;

                  import spark.components.NavigatorContent;

                  import spark.components.TextInput;

                  import spark.events.TextOperationEvent;

                  import spark.layouts.HorizontalAlign;

                  import spark.skins.mobile.TextInputSkin;

                 

                  import vo.ProdutoVO;

                 

                  [Bindable]

                  private var txtQtd:TextInput;

                 

                  protected function iconitemrenderercustomizado1_dataChangeHandler(event:FlexEvent):void

                  {

                      if(data.arquivo != null) {

                          var loader:Loader = new Loader();

                          loader.contentLoaderInfo.addEventListener(Event.COMPLETE, setIcon);

                          loader.loadBytes(data.arquivo);

                      }

                  }

                 

                  private function setIcon(event : Event) : void {

                      var info:LoaderInfo = LoaderInfo(event.target);

                      var b : Bitmap = Bitmap(info.loader.content);

                      icone = b.bitmapData;

                      createIconDisplay();

                  }

                 

                  private var i:int = 0;

                 

                  protected function iconitemrenderercustomizado1_initializeHandler(event:FlexEvent):void

                  {

                      if (!txtQtd) {                   

                          txtQtd = new TextInput();

                          txtQtd.id = "txt" + i++.toString();

                          txtQtd.width = 70;

                          txtQtd.height = 40;

                          txtQtd.x = this.parent.width-90;

                          txtQtd.y = 25;

                          txtQtd.maxChars = 4;

                          txtQtd.setStyle("skinClass", spark.skins.mobile.TextInputSkin);

                          txtQtd.softKeyboardType = SoftKeyboardType.NUMBER;

                          txtQtd.addEventListener(TextOperationEvent.CHANGE, verificarProduto);

                          this.addChild(txtQtd);

                      }

                  }

                 

                  override public function set data(value:Object):void

                  {

                      if(value != null)

                      {

                          super.data = value;

                         

                          if ( value.quantidade > 0) {

                              txtQtd.text = value.quantidade;

                          }

                      }

                  }

                 

                  protected function verificarProduto(event:TextOperationEvent):void

                  {

                      ProdutoVO(this.data).quantidade = parseInt( txtQtd.text );

                     

                      if (txtQtd.text != "" && txtQtd.text != "0") {

                          // adiciona ao pedido

                          SFAUtils.getInstance().adicionarProdutoAoPedido(

                              ProdutoVO(this.data),

                              SFA(parentApplication).pedido,

                              SFA(parentApplication).usuario);

                      } else {

                          //remove do pedido, quantidade vazia ou zero

                          SFAUtils.getInstance().removerProdutoDoPedido(

                              ProdutoVO(this.data),

                              SFA(parentApplication).pedido)

                      }

                  }

                 

              ]]>

          </fx:Script>

      </componentes:IconItemRendererCustomizado>

       

      3. The value strange behavior:

      foto2.png

       

      Any suggestions what could be????

        • 1. Re: TextInput in List
          Shongrunden Adobe Employee

          I haven't looked very closely at your code, but did notice this:

           

                      override public function set data(value:Object):void

                      {

                          if(value != null)

                          {

                              super.data = value;

                            

                              if ( value.quantidade > 0) {

                                  txtQtd.text = value.quantidade;

                              }

                          }

                      }

           

          If you remember to clear the textinput value when its not > 0 does that help?

           

                      override public function set data(value:Object):void

                      {

                          if(value != null)

                          {

                              super.data = value;

                            

                              if ( value.quantidade > 0) {

                                  txtQtd.text = value.quantidade;

                              }

                              else {

                                   txtQtd.text = "";

                              }

                          }

                      }

          • 2. Re: TextInput in List
            thiagollo Level 1

            Right there!!!!

             

            This is a very simple error and i dont even saw.

             

            Thank you!