1. 程式人生 > >監聽輸入框

監聽輸入框

/**
     * 輸入框監聽
     */
    private void initEdtTxt() {
        edtTxtDescribe.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) {

                String content = edtTxtDescribe.getText().toString();
                if (content.length() > 0) {
                    int size = 120 - content.length();
                    tvCount.setText(size + "");
                } else {
                    tvCount.setText("120");
                }
                if (content.length() == 120) {
                    IToast.showShort(BuyerRateActivity.this, "不能再輸入");
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });
    }