Issue
Im creating a convertor application. I want to set the EditText so that when the user is inputting the number to be converted, a thousand separator (,
) should be added automatically in realtime to the number once it increments by 3 figures: thousand, million, billion etc.
And when erased to below 4 figures the number goes back to normal.
Any help?
Solution
You can use String.format()
in a TextWatcher
. The comma in the format specifier does the trick.
This does not work for floating point input. And be careful not to set an infinite loop with the TextWatcher.
public void afterTextChanged(Editable view) {
String s = null;
try {
// The comma in the format specifier does the trick
s = String.format("%,d", Long.parseLong(view.toString()));
} catch (NumberFormatException e) {
}
// Set s back to the view after temporarily removing the text change listener
}
Answered By - Dheeraj Vepakomma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.