사용자가 소수점 이하 3 자리가있는 숫자를 입력하지 못하도록하는 EditText가 있습니다.안드로이드 : 사용자가 3 자리가 넘는 숫자를 입력하는 것을 방지하는 방법
numeric(15, 3)
내가 어떻게 할 수있는 당신이 어떤 생각을 가지고 있습니까 :이 때문에 나는이 데이터 유형은 한 전화에서 보내는 데이터를 저장하는 것입니다 SQL 서버의 데이터베이스에? 이것은 내가 뭘하려
android:maxLength="15"
android:lines="1"
android:inputType="numberDecimal"
편집
을 :
는 이미이 값을 설정했지만, 그들은 부분적으로 만 나에게 도움이 될
mQuantityEditText.addTextChangedListener(new TextWatcher(){
@Override
public void afterTextChanged(Editable s) {
String str = mQuantityEditText.getText().toString();
DecimalFormat format=(DecimalFormat) DecimalFormat.getInstance();
DecimalFormatSymbols symbols=format.getDecimalFormatSymbols();
char sep=symbols.getDecimalSeparator();
int indexOFdec = str.indexOf(sep);
if(indexOFdec >=0) {
if(str.substring(indexOFdec,str.length()-1).length() >3)
{
s.replace(0, s.length(),str.substring(0, str.length()-1));
}
}
}
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
});
그것은 그것 때문에 일에만 소수점 이하 3 자리까지 허용하지만 숫자에 맞게 최대 자릿수를 제어하는 방법을 아직 모르겠습니다.
미리 감사드립니다.
소수점 이하 3 자리로 반올림 한 숫자. – biegleux
여기 좀 보시라. http://stackoverflow.com/questions/5357455/limit-decimal-places-in-android-edittext –
onTextChange 리스너를 구현하고 정규식을 수행하는 것이 어떨까요? –