2011-09-28 20 views

答えて

139

この

editText.setOnEditorActionListener(new OnEditorActionListener() {   
    @Override 
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
     if(actionId==EditorInfo.IME_ACTION_DONE){ 
      //do something 
     } 
    return false; 
    } 
}); 
+1

ありがとう、それは働いた... –

15

は、それは両方のDONERETURNのために働くこの

をしてみてみてください。

EditText editText= (EditText) findViewById(R.id.editText); 
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() { 

       @Override 
       public boolean onEditorAction(TextView v, int actionId, 
         KeyEvent event) { 
        if (event != null && event.getKeyCode() == KeyEvent.KEYCODE_ENTER 
          || actionId == EditorInfo.IME_ACTION_DONE) { 
         // Do your action 
         return true; 
        } 
        return false; 
       } 
      }); 
0

KeyEventをキャッチして、そのキーコードを確認します。 FLAG_EDITOR_ACTIONは、そのキーを入力して「次へ」またはドキュメントhereを探す

if (event.getKeyCode() == KeyEvent.FLAG_EDITOR_ACTION) 
    //your code here 

を「完了」オート標識されているIMEから来ているキーを入力識別するために使用されます。

第二の方法は、

myEditText.setOnEditorActionListener(new OnEditorActionListener() { 
@Override 
public boolean onEditorAction(TextView view, int actionId, KeyEvent event) { 
    int result = actionId & EditorInfo.IME_MASK_ACTION; 
    switch(result) { 
    case EditorInfo.IME_ACTION_DONE: 
     // done stuff 
     break; 
    case EditorInfo.IME_ACTION_NEXT: 
     // next stuff 
     break; 
    } 
} 
}); 
0

ウルは、赤い線が直面している場合は、キーボードが符号または横の矢印記号

YourEdittextName.setOnEditorActionListener(new TextView.OnEditorActionListener() 
    { 
     @Override 
     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) 
     { 
      if(actionId== EditorInfo.IME_ACTION_DONE||actionId==EditorInfo.IME_ACTION_NEXT) 
      { 
       //Perform Action here 
      } 
      return false; 
     } 
    }); 

を入力して表示されているかどうか、これは

これは、両方の状態で動作します試してみてください次にこれを実行します... import alte + enterを押すとKeyeventとEditorInfoが表示されます それから、すべてのエラーが正しく削除されます.......

関連する問題