2012-02-13 77 views
0

我如何知道編輯文本完成編輯的時間?就像用戶選擇下一個方框時一樣,或者按下軟鍵盤上的完成按鈕。Android我如何知道編輯文本已完成編輯?

我的代碼是在這裏

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; 
} 

每個字符輸入我的alertbox後彈出。基本上我想獲得輸入文本時,我將焦點更改爲下一個EditText框,並獲得失去焦點edittext的價值,並與prevoius值比較可以任何一個給出任何解決方案 在此先感謝。

+0

http://stackoverflow.com/questions/8063439/android-edittext-finished-typing-event – Rakhita 2012-02-13 07:16:27

回答

0

在你的情況下,我可能會給你的最好建議是在對話框中接收用戶的輸入並將它們返回到TextView字段。通過這種方式,當用戶在對話框中按下確定時,它可能會觸發您的自定義代碼,使用之前輸入的文本進行任何您想要的操作。

如果你正在考慮完成鍵盤上關鍵事件,那麼它並不可靠,因爲用戶可能也只需按下它使鍵盤完成事件不會去挑釁

0

你導航到下一個的EditText實現類似於:EditText的OnEditorActionListener。

0

您的editText必須設置一個OnEditorActionListener。你可以像這樣定義一個EditorActionListener:

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; 
     } 
    };