hi-

i'm writing a custom edittext class that formats my text based on input.  
included here is a simplified version that separates text by dashes.
the screenshot shows two instances of my class, one with "hasdirectionallayout" 
not set and another with "hasdirectionallayout" set to true:

  http://i.imgur.com/AoBSN.png

the first editext instance shows the proper behavior: you type a character, the 
character is displayed and appends a "-", and sets the selection position at 
the end of the field, where you can continue typing more characters.

the second edittext instance shows incorrect behavior: you type a character, 
the character is displayed and appends a "-", but it doesn't set the selection 
position at the end of the field - it loses focus, so you can't type into the 
edittext unless you click back into it.

two points to make:

1) setting "hasdirectionallayout=true" changes the behavior of the edittext, 
which seems wrong.
2) my general approach of overriding "setValue" in order to format my text may 
not be optimal 

i'm interested in the answer to point 1 more than point 2 - unless there is a 
different approach to point 2 that still allows me to use 
"hasdirectionallayout=true".

sample code below.

thanks,
augusto.

====
<canvas height="100%" width="100%">
        <simplelayout axis="y" spacing="10"/>

        <class name="dashes" extends="edittext">
                <attribute name="process" type="boolean" value="true"/>
                <method name="setValue" args="t, isinitvalue=null">
                        if (t == null || t == '') {
                                return;
                        }
                        if (!process) {
                                super.setValue(t, isinitvalue);
                                return;
                        }

                        t += "-"; 
                        setAttribute('process', false);
                        setAttribute('text', t);
                        setAttribute('process', true);

                        if (this['field'] != null)
                                field.setSelection(t.length);
                </method>
        </class>

        <text>works:</text>
        <dashes/>
        <text>doesn't work:</text>
        <dashes hasdirectionallayout="true"/>
</canvas>
====

Reply via email to