txtAmount = (EditText) findViewById(R.id.amount);
txtAmount.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
String text = s.toString();
if (text.contains(".")) {
int index = text.indexOf(".");
if (index + 3 < text.length()) {
text = text.substring(0, index + 3);
txtAmount.setText(text);
txtAmount.setSelection(text.length());
}
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
@Override
public void afterTextChanged(Editable s) {
// TODO Auto-generated method stub
}
});