Change KEYBOARD LANGUAGE android

1

Currently I find that using my MASCARA class for the amounts written, as the phone reacts differently, this is my mask class

    public class Mask implements TextWatcher {

private DecimalFormat df;
private DecimalFormat dfnd;
private boolean hasFractionalPart;
private int trailingZeroCount;

private EditText et;

public Mask(EditText et)
{
    df = new DecimalFormat("#,###.##");
    df.setDecimalSeparatorAlwaysShown(true);
    dfnd = new DecimalFormat("#,###");
    this.et = et;
    hasFractionalPart = false;
}

@SuppressWarnings("unused")
private static final String TAG = "NumberTextWatcher";

@Override
public void afterTextChanged(Editable s)
{
    et.removeTextChangedListener(this);

    try {
        int inilen, endlen;
        inilen = et.getText().length();

        String v = s.toString().replace(String.valueOf(df.getDecimalFormatSymbols().getGroupingSeparator()), "");
        Number n = df.parse(v);
        int cp = et.getSelectionStart();
        /*if (hasFractionalPart) {
            et.setText(df.format(n));
        } else {
            et.setText(dfnd.format(n));
        }*/
        if (hasFractionalPart) {
            StringBuilder trailingZeros = new StringBuilder();
            while (trailingZeroCount-- > 0)
                trailingZeros.append('0');
            et.setText(df.format(n) + trailingZeros.toString());
        } else {
            et.setText(dfnd.format(n));
        }

        endlen = et.getText().length();
        int sel = (cp + (endlen - inilen));
        if (sel > 0 && sel <= et.getText().length()) {
            et.setSelection(sel);
        } else {
            // place cursor at the end?
            et.setSelection(et.getText().length() -1 );
        }
    } catch (NumberFormatException nfe) {
        // do nothing?
    } catch (ParseException e) {
        // do nothing?
    }

    et.addTextChangedListener(this);
}

@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after)
{
}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count)
{
    int index = s.toString().indexOf(String.valueOf(df.getDecimalFormatSymbols().getDecimalSeparator()));
    trailingZeroCount = 0;
    if (index > -1)
    {
        for (index++; index < s.length(); index++) {
            if (s.charAt(index) == '0')
                trailingZeroCount++;
            else {
                trailingZeroCount = 0;
            }
        }

        hasFractionalPart = true;
    } else {
        hasFractionalPart = false;
    }
    /*if (s.toString().contains(String.valueOf(df.getDecimalFormatSymbols().getDecimalSeparator())))
    {
        hasFractionalPart = true;
    } else {
        hasFractionalPart = false;
    }*/

}

Install my application on 2 phones that I have a J5 2016 and a J7 Prime 2016

here the photos screens

As you can see in one of the photos, if it is correct, mark MILES with comma and decimals with period, but in the other mark thousands with period so I can not put commas for decimals, and it is the same application installed on 2 phones, so I imagine it could be the language or something like that, there is some way through android studio to tell you to use X region or language, thank you already

    
asked by Bruno Sosa Fast Tag 03.11.2017 в 14:41
source

1 answer

2

You can try this library that allows you to assign a mask to EditText and you do not have to do it by hand:

compile 'br.com.jansenfelipe: androidmask: 1.0.1'

You have to download the .jar from here and include it in the ☻lib folder:

link

To use it, you just have to do this:

EditText etPrueba;
etPrueba = (EditText) findViewById(R.id.ETprueba);

MaskEditTextChangedListener maskCPF = new 
MaskEditTextChangedListener("#,###.##", etPrueba);

etPrueba.addTextChangedListener(maskCPF);

I hope it solves your problem.

Information obtained from: link

    
answered by 07.11.2017 / 11:59
source