0

How do I know when my edit text is done being edited? Like when the user selects the next box, or presses the done button on the soft keyboard.

My Code is Here

EditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {

      public void onFocusChange(View arg0, boolean arg1) {

      int tag=(Integer) arg0.getTag();
      final EditText Caption = (EditText) arg0;

      previous_Meter_Reading = new HashMap<String, String>();
      previous_Meter_Reading = c.get(tag); 
      String pre =previous_Meter_Reading.get("previousMeterReading");
      previous =Integer.parseInt(pre);


      Log.i("out",pre);


      if (!arg1 && ! Caption.getText().toString().equals("")) {

      int pos=arg0.getId();           
      Log.i("Tag", arg0.getTag().toString());

      Current = Integer.valueOf(Caption.getText().toString());
      if(Current<previous){
          AlertDialog.Builder builder = new AlertDialog.Builder(
                    context);
            builder.setTitle("WARNING");
            builder.setIcon(android.R.drawable.ic_dialog_alert);
            builder.setMessage("Current value should be greater");
            builder.setPositiveButton("ok",
                    new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int which) {
                            // TODO Auto-generated method stub

                        }
                    });

            AlertDialog diag = builder.create();
            diag.show();
      }





      Toast.makeText(context, "Focus Changed",Toast.LENGTH_SHORT);

      }

      } });


    return view;
}

after each character is entered my alertbox is popup. basically i want to get input text when i change the focus to next EditText box and get the value of lost focus edittext and compare with prevoius value can any one give any solution for that Thanks in advance.

Sachin Gurnani
  • 2,444
  • 7
  • 36
  • 45

3 Answers3

0

Your editText must set an OnEditorActionListener. You can define an EditorActionListener like this:

OnEditorActionListener mListener = new TextView.OnEditorActionListener(){

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                //do stuff here
            }
                return true;
        }
    };
ginsengtang
  • 751
  • 1
  • 7
  • 17
0

in your case, the best suggestion I may give you is to receive user's input in dialog boxes and return them back to TextView fields. In this way, when user press OK inside dialog box, it may trigger your custom code to do what ever you want with the previously entered text.

If you are considering Done key event on keyboard, then its not reliable because a user may navigate to next EditText too just by pressing it causing the keyboard Done event not to be provoked

waqaslam
  • 67,549
  • 16
  • 165
  • 178
0

You have to implement something like : OnEditorActionListener for the EditText.

Shreyash Mahajan
  • 23,386
  • 35
  • 116
  • 188