나는 지불을 위해 EditText를 구현했습니다. 입력 한 숫자에 따라 그 금액이 초기 금액에서 뺀 다음 위의 TextView에 TextWatcher를 통해 표시됩니다. 입력 할 때 숫자 입력 유효성 확인
나는 이것을 달성하기 위해 TextWatcher를 사용하고 있습니다. 입력 된 값이 가격보다 더 많은 경우)
1 :
et_EnterInstallment.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
//To decrease the amount entered from the price (amount as displayed in textview)
String editTextValue = et_EnterInstallment.getText().toString();
if(!editTextValue.isEmpty()) {
int mainPrice = Integer.parseInt(price);
int enteredPrice = Integer.parseInt(et_EnterInstallment.getText().toString());
int valueAfterDeduction = mainPrice - enteredPrice;
tv_Price.setText(String.valueOf(valueAfterDeduction));
} else {
tv_Price.setText(price);
}
}
});
어떻게 다음 달성하기 위해 글고 값의 유효성을 검사 할 수 있습니다. 어떤 경우에 사용자는 필드에 해당 번호를 입력 할 수 없습니다 (가격이 3000이고 사용자가 350을 입력하고 다른 0을 입력하려고하면 가격이 더 높아져서 0 또는
다음 답변을 따르십시오. 그것은 나를 위해 작동합니다. https://stackoverflow.com/a/14212734/3822391 – Avinash