I'm implementing EditText
's and I'm facing with one issue... I've put that the inputType
is numberDecimal
but at the time I type on the EditText
I'd like to put the "." or "," autommatically...
I can put for example 100.00
or 90.00
it depends of the user... Can it be possible?
I tried to create a TextWatcher
and do some things on onTextChanged
like see if the charSequence-lenght()==2
add a "." or "," but doesn't work...
Can I detect when to put the comma or dot even if I have a decimal format like ##.##
or ###.##
? As I said it can be 100.00
or 80.00
.
Edit
@Override
public void afterTextChanged(Editable editable) {
//et1 and et2 are not empty
if(et1.getText().toString().length() == 5 && et2.getText().toString().length() == 5){
double pe1 , pe2;
pe1 = Double.parseDouble(et1.getText().toString());
pe2 = Double.parseDouble(et2.getText().toString());
double res = (pe1+pe2)/2;
String formattedString = String.format("%,.2f", res);
tvPr.setText(formattedString);
}
The problem is on the textInput not on afterTextChanged
I guess... because I have to put the "." manually and I want to avoid this.
EDIT2
Also a friend of mine suggested to me that I could ignore the . and , and since the marks are always 100, 80, 32, etc... on the editText just type those numbers but then tract those as a double and I'd like to put a ,00 when the user finish the editting of editText is that possible?
Are the comparation if(et1.getText().toString().length() == 5 && et2.getText().toString().length() == 5){
good at the time to check wheter is an edittext not empty? I have to update a TextView once both edittext are not empty and do some operations so, I tried this way, is there another one better? (I put lenght()==5 because on EditText I put maxlenght() = 5;