How to force a numeric entry in android to work with comma instead of point to decimal numbers?

2

I already tried to use Culture but it did not work either and I did not want to make a mistake of putting a replace before sending it to the base. Neither with the XLab I was able to put the keyboard to work me ptbr and to let put comma instead of point. Does anyone have a more luxurious solution?

    
asked by anonymous 19.05.2015 / 16:18

1 answer

1

I found a solution on Xamarin forum (source code is on end of the response)

You should create a custom keyboard layout (resource XML) . This code below is already customized for your needs:

<Keyboard xmlns:android="http://schemas.android.com/apk/res/android"
    android:keyWidth="33%p" android:horizontalGap="0px"
    android:verticalGap="0px" android:keyHeight="54dip">

    <Row>
        <Key android:codes="8" android:keyLabel="1" android:keyEdgeFlags="left" />
        <Key android:codes="9" android:keyLabel="2" />
        <Key android:codes="10" android:keyLabel="3" android:keyEdgeFlags="right" />
    </Row>

    <Row>
        <Key android:codes="11" android:keyLabel="4" android:keyEdgeFlags="left" />
        <Key android:codes="12" android:keyLabel="5" />
        <Key android:codes="13" android:keyLabel="6" android:keyEdgeFlags="right" />
    </Row>

    <Row>
        <Key android:codes="14" android:keyLabel="7" android:keyEdgeFlags="left" />
        <Key android:codes="15" android:keyLabel="8" />
        <Key android:codes="16" android:keyLabel="9" android:keyEdgeFlags="right" />
    </Row>

    <Row>
        <Key android:codes="67" android:keyIcon="@drawable/sym_keyboard_delete"
            android:iconPreview="@drawable/sym_keyboard_delete"
            android:keyEdgeFlags="left" />
    <Key android:codes="55" android:keyLabel="," />
        <Key android:codes="7" android:keyLabel="0" />
        <Key android:codes="66" android:keyEdgeFlags="right"
            android:keyIcon="@drawable/sym_keyboard_feedback_return"
            android:iconPreview="@drawable/sym_keyboard_feedback_return" />
    </Row>

</Keyboard>

Using the custom keyboard:

public class Activity1 : Activity
{
    public CustomKeyboardView mKeyboardView;
    public View mTargetView;
    public Keyboard mKeyboard;
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);

        mKeyboard = new Keyboard(this, Resource.Xml.keyboard2);
        mTargetView = (EditText)FindViewById(Resource.Id.target);

        mKeyboardView = (CustomKeyboardView)FindViewById(Resource.Id.keyboard_view);
        mKeyboardView.Keyboard = mKeyboard;

        mTargetView.Touch += (sender, e) => {
            Log.Info("onTouch", "true");
            ShowKeyboardWithAnimation();
            e.Handled = true;
        };

        mKeyboardView.Key += (sender, e) => {
            long eventTime = JavaSystem.CurrentTimeMillis();
            KeyEvent ev = new KeyEvent(eventTime, eventTime, KeyEventActions.Down, e.PrimaryCode, 0, 0, 0, 0, KeyEventFlags.SoftKeyboard | KeyEventFlags.KeepTouchMode);

            this.DispatchKeyEvent(ev);
        };
    }

    public void ShowKeyboardWithAnimation()
    {
        Log.Info("keyboardState", mKeyboardView.Visibility.ToString());
        if (mKeyboardView.Visibility == ViewStates.Gone)
        {
            Animation animation = AnimationUtils.LoadAnimation(
                this,
                Resource.Animation.slide_in_bottom
            );
            mKeyboardView.ShowWithAnimation(animation);
        }
    }
}

Usethisandroidcodetableforcustomization: KeyEvent

Source Code: CustomKeyboard.zip

    
19.05.2015 / 22:21