如何使用EditText和onTextChanged

时间:2012-09-24 06:13:00

标签: java android eclipse

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

   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());

0 个答案:

没有答案