从方法直接初始化TextWatcher有什么区别?

时间:2019-07-25 05:34:55

标签: java android

方法1:当我直接初始化文本查看器时,“ etOtp1MobNoVer”不为null。

private final TextWatcher otp1TextWatcher = 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) {
        if (s != null)
            checkNProceedForTextChanged(etOtp1MobNoVer, s);
    }
};

方法2:当我从方法etOtp1MobNoVer初始化TextWathcer时为空。

private final TextWatcher otp1TextWatcher = textWatcher(etOtp1MobNoVer);

@NonNull
private TextWatcher textWatcher(ET etOtp1MobNoVer) {
    return 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) {
            if (s != null)
                checkNProceedForTextChanged(etOtp1MobNoVer, s);
        }
    };
}

0 个答案:

没有答案