android Textview text monitoring of Textview usage

  • 2020-05-19 05:51:58
  • OfStack

1. First add an textchangedlistener to the user
2. Then write a text change monitor


mobile_et.addTextChangedListener(textWatcher);

    /**
     *  Real-time monitoring of user input mobile phone number, input to the last 1 After bit, calculate the amount of discount 
     */
    TextWatcher textWatcher = new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            if(s.length() == 11){
                String amountYuan = amount_et.getText().toString();// The amount selected by the user + yuan 
                String mobileNum = mobile_et.getText().toString().trim();
                int tMobile = Utils.getMobileOp(mobileNum);

                String disAmount= getDisAmount(tMobile, amountYuan);
                amount_discount_tv.setText(disAmount);
            }
        }
    };


Related articles: