I have text editing. I want to enter decimal values ββinto it.
that is, when I enter the first number. It should look like this:.01
then I enter the second number. it should be like this:.12
then for the third. It should look like this:1.23
it will go like this ... how to implement this scenario on the Android platform . Any idea?
Edit:
I have tried this. But I got a StackOverFlowError when I add a line to EditText. I posted my code below:
amount.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
try {
if (s.length() == 1) {
Float f = Float.parseFloat(s.toString()) / 100;
System.out.println(String.valueOf(f));
amount.setText("");
amount.append(String.valueOf(f));
} else if (s.length() > 1) {
String str = s.toString().replace(".", "");
Float f = Float.parseFloat(str) / 100;
System.out.println(String.valueOf(f));
amount.setText("");
amount.append(String.valueOf(f));
}
} catch (Exception e) {
}
}
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
public void onTextChanged(CharSequence s, int start, int before,
int count) {
}
});
source
share