0

我为 5 个 EditTexts 创建了一个 Common TextWatcher。如何检测 onTextChanged for EditText 中的文本更改?

   private  class CustomTextWatcher implements TextWatcher {
            double valuesMeasure;
            public void beforeTextChanged(CharSequence s, int start, int count,int after) {}
            public void onTextChanged( final CharSequence s, int start, int before,int count) 
            {
                checkEditTextIsFilledorNot();
                try
                {
                valuesMeasure=Double.valueOf(s.toString());}
                catch(Exception e)
                {Log.i("Error", e.getMessage());}
                if(valuesMeasure==0)
                {
                }
                else if(valuesMeasure>=0.001&&valuesMeasure<=30.000)
                {
                }
                else
                {
                    AlertDialog.Builder builder = new AlertDialog.Builder(TrapezoidalActivity.this);
                    builder.setMessage("Enter All Values Betweeen 0.001 and 30 for all the fields.")
                    .setCancelable(false)
                    .setNegativeButton("Close", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            s.subSequence(0,s.length()-1);
                            s.toString();
                            dialog.cancel();
                        }
                    });
                    AlertDialog alert = builder.create();
                    alert.show();
                }

            }
            public void afterTextChanged(Editable s) {
            }
        }

以上是我的代码...如何在 Edittext 中获取文本更改?
我这样称呼Edittext

edittext.addTextChangedListener(new CustomTextWatcher());
4

0 回答 0