2013-05-31 45 views
1

我正在使用android。在我的登錄頁面我有一個提交按鈕,它工作正常。現在我需要讓android鍵盤的「完成」按鈕動作具有提交按鈕的相同功能。我怎樣才能做到這一點?任何幫助都會提前感激。Android完成按鈕動作onclick

回答

5

您需要爲Editext實施OnEditorActionListener。像

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

這是我發現

class DoneOnEditorActionListener implements OnEditorActionListener { 
@Override 
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
    if (actionId == EditorInfo.IME_ACTION_DONE) { 
     InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE); 
     imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 
     return true;  
    } 
    return false; 
} 

}

來源:

http://savagelook.com/blog/android/android-quick-tip-edittext-with-done-button-that-closes-the-keyboard

你應該做更多的谷歌搜索

0

試試用OnEditorActionListener

EditText edit = (EditText)findViewById(R.id.edit); 

     edit.setOnEditorActionListener(new OnEditorActionListener() { 
      public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
       if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) { 
        Log.i("check","Enter pressed"); 
       }  
       return false; 
      } 
     });