1 つの Ediitext 金額フィールドを含む 1 つのリサイクラー ビュー アダプターを作成しました。その edittext に textwatcher を適用して現在のオブジェクトに値を保存しましたが、いくつかの条件に基づいて金額フィールドの値を変更したい場合、たとえば、値 100 を入力している場合範囲は0から50で、自動的にゼロとして保存するか、エラーメッセージを表示する必要があります
以下は私が使用したコード部分です
this.edtAmount.addTextChangedListener(amountTextWatcher);
private class AmountTextWatcher implements TextWatcher {
private int position;
public void updatePosition(int position) {
this.position = position;
}
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
// no op
Log.d("Entered Val", "Values" + charSequence.toString());
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
Log.d("Entered Val", "Values" + charSequence.toString());
String amountStr=charSequence.toString().trim();
String pdcAmount=collections.get(position).getPdcAmt();
String balanceDue=collections.get(position).getAmountdue();
if(Constants.checkString(amountStr)){
collections.get(position).setAmountpaid(0);
return;
}
double amount=Constants.getRoundAmountDouble(decimalplace,amountStr);
double balance=Constants.getRoundAmountDouble(decimalplace,balanceDue);
if(!Constants.checkString(pdcAmount)){
balance= balance-Constants.getRoundAmountDouble(decimalplace,pdcAmount);
}
if(balance==0){
collections.get(position).setAmountpaid(0);
return;
}else if(balance<0 && (amount>0 || amount<balance)){
collections.get(position).setAmountpaid(0);
return;
}else if(balance>0){
if(amount<0){
collections.get(position).setAmountpaid(0);
return;
}else if(amount>balance){
collections.get(position).setAmountpaid(0);
return;
}
}
collections.get(position).setAmountpaid(amount);
if(!onbind)
notifyItemChanged(position);
}
@Override
public void afterTextChanged(Editable charSequence) {
}
}
しかし、私が編集テキストに入力しているすべての文字でフォーカスが失われています
ご意見をお聞かせください
ありがとう