0

I have created one recycler view adapter which contains one Ediitext amount field, I have applied textwatcher on that edittext to save value in currenct object and but I want to change value of amount field based on some conditions ,For example if I am entering value 100 and range is 0 to 50 then automatically it should save as zero or give some error message

Below is code portion that I have used

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) {



        }


    }

But with every character i am entering edittext is loosing focus

Please advice

Thanks

bindal
  • 1,940
  • 1
  • 20
  • 29

0 Answers0