When we work with the currency we need to use ',' separator in appropriate places . For example 1500 as 1,500.
I have a issue. My applications require formatting the EditText's value while typing. I.E., a number that needs to be formatted with decimal and thousands separators. Example, I input 123456789, the EditText display 123.456.789.
How to I do this issue ? Thank all.
Related
I have an android application that shall correspond to French localization, where the Decimal Format for numbers shall have the Decimal Separator as "," rather than ".",
I need to let the EditText by default separate the decimal number with "," when entering a number in the EditText, where adding a textWatcher on every numeric field isn't an option, as there are many numeric fields, and many locales in which the user may run the application accordingly, and accordingly adding a text watcher for each locale isn't an option,
What am trying to do is to set the application DecimalFormatSymbols on login according to logged in culture, and accordingly all numeric EditText controls shall append the specified DecimalSeparator according to what specified after login via Example: using the method DecimalFormatSymbols.setDecimalSeparator(','),
Is that doable,
Please Advise!
Workaround
char separator = DecimalFormatSymbols.getInstance().getDecimalSeparator();
editText.setKeyListener(DigitsKeyListener.getInstance("0123456789" + separator));
I have a issue. My applications require formatting the EditText's value while typing. I.E., a number that needs to be formatted with decimal and thousands separators. Example, I input 123456789, this number must appear 123.456.789.
How to I do this issue ? Thank all.
Нou can implement TextWatcher to your editText. Here're useful links for you:
How to use the TextWatcher class in Android?
http://developer.android.com/reference/android/text/TextWatcher.html
There you need to upgrade your number.
Or you can create your own customEditText.
I want a user to be able to input numbers such as the following.
Valid:
~0
~0.00
~12.34
~301.7
~4
Invalid
~01
~3.001
In short, it allows decimal numbers up to two decimal places.
This is what I've been trying to use
Pattern mPattern = Pattern.compile("|(0|[1-9]+[0-9]*)(\\.[0-9]{1,2})?");
When I try to type a "." in the field, it won't let me.
I think the problem is that your validation pattern needs to match the input as you are entering it. In your case, as soon as you type in the ".", your entry is invalid. For example, if you are trying to enter 1.23, when you are entering the decimal point your entry becomes 1., which does not match your regexp.
Try replacing {1,2} with {0,1,2} in your expression to allow a trailing ".".
I discovered today that Android can't display a small handful of Japanese characters that I'm using in my Japanese-English dictionary app.
The problem comes when I attempt to display the character via TextView.setText(). All of the characters below show up as blank when I attempt to display them in a TextView. It doesn't appear to be an issue with encoding, though - I'm storing the characters in a SQLite database and have verified that Android can understand the characters. Casting the characters to (int) retrieves proper Unicode decimal escapes for all but one of the characters:
String component = cursor.getString(cursor.getColumnIndex("component"));
Log.i("CursorAdapterGridComponents", "Character Code: " + (int) component.charAt(0) + "(" + component + ")");
I had to use Character.codePointAt() to get the decimal escape for the one problematic character:
int codePoint = Character.codePointAt(component, 0);
I don't think I'm doing anything wrong, and as String's are by default UTF-16 encoded, there should be nothing preventing them from displaying the characters.
Below are all of the decimal escapes for the seven problematic characters:
⺅ Character Code: 11909(⺅)
⺌ Character Code: 11916(⺌)
⺾ Character Code: 11966(⺾)
⻏ Character Code: 11983(⻏)
⻖ Character Code: 11990(⻖)
⺹ Character Code: 11961(⺹)
𠆢 Character Code: 131490(𠆢)
Plugging the first six values into http://unicode-table.com/en/ revealed their corresponding Unicode numbers, so I have no doubt that they're valid UTF-8 characters.
The seventh character could only be retrieved from a table of UTF-16 characters: http://www.fileformat.info/info/unicode/char/201a2/browsertest.htm. I could not use its 5-character Unicode number in setText() (as in "\u201a2") because, as I discovered earlier today, Android has no support for Unicode strings past 0xFFFF. As a result, the string was evaluated as "\u201a" + "2". That still doesn't explain why the first six characters won't show up.
What are my options at this point? My first instinct is to just make graphics out of the problematic characters, but Android's highly variable DPI environment makes this a challenging proposition. Is using another font in my app an option? Aside from that, I really have no idea how to proceed.
Is using another font in my app an option?
Sure. Find a font that you are licensed to distribute with your app and has these characters. Package the font in your assets/ directory. Create a Typeface object for that font face. Apply that font to necessary widgets using setTypeface() on TextView.
Here is a sample application demonstrating applying a custom font to a TextView.
I have an EditText-Object in my Android App where the user can input a "street number". Because street number may also consit of characters, character input should not be disabled at all, rather it numeric input should just be preselected and if the user wants he can also switch to character input.
Until now I could not find any combination of Flags using
editText.setInputType(...);
Possible allowed entries in the EditText would be:
23a-26b
This always disallows some other input type, but what I want is just a preselected inputType.
Any ideas?