调用EditText addTextChangeListener时应用崩溃

时间:2018-08-06 23:13:42

标签: android android-edittext fatal-error addtextchangedlistener

在EditText中输入新输入时,它会崩溃并关闭应用程序

我无法确定崩溃的原因: 以下是到目前为止我尝试过的代码:

注意:创建的“ HelperMethods”已经过测试,可以完成工作

    // get the entered A.R.D from user
    final EditText A_R_D_EditText = (EditText) rootview.findViewById(R.id.A_R_D_Value);
    A_R_D_EditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            charSequence = Double.toString(Last_ARD_input_value);
            A_R_D_EditText.setText(charSequence);
            ;
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            if (charSequence.length() == 0) {
                // check is a valid number
                double number = Double.parseDouble(charSequence.toString());
                if (HelperMethods.check_valid_number(number, 1)) {
                    A_R_D_value_deci = number;
                    A_R_D_value_degree = HelperMethods.convert_to(number, 1, 0);
                    A_R_D_value_mils = HelperMethods.convert_to(number, 1, 2);
                    Last_ARD_input_value = number;
                } else {
                    Toast.makeText(getContext(), " Please enter a valid number ", Toast.LENGTH_LONG).show();
                }
            } else {
                Toast.makeText(getContext(), " Please enter a valid number ", Toast.LENGTH_LONG).show();
            }
        }

        @Override
        public void afterTextChanged(Editable editable) {
            // set A_R_D_value_degree
            TextView A_R_D_degree_textview = (TextView) rootview.findViewById(R.id.A_R_D_Value_degree);             A_R_D_degree_textview.setText(Double.toString(A_R_D_value_degree));
            // set A_R_D_value_mils
            TextView A_R_D_mils_textview = (TextView) rootview.findViewById(R.id.A_R_D_Value_mils);
            A_R_D_mils_textview.setText(Double.toString(A_R_D_value_mils));

        }
    }); 

0 个答案:

没有答案