Something Like this should do it:
@Override
public void afterTextChanged(Editable s) {
String val = billTotal.getText().toString();
String newStringContent = convertToDollarsAndCents(val);
// change string to reflect your desired format
billTotal.setText(newStringContent)
}
public String convertToDollarsAndCents(String val) {
if(!val.contains(".") {
if(val.length<=2) {
return val+".00"
}
else {
return val.subString(0, val.length-2)+"."+val.subString(val.length-2, val.length)
}
}
}
The substring code might not be exactly right, but it ought to get it done with some tweaking.
The other option is to make your input a number input as you can configure an inputType for your EditText:
<EditText android:inputType="number" ... />
ANd put the onus on the user to indicate if they want cents or not.