2013-07-05 25 views
-3

如何在我的方法正在運行時禁用鍵盤,並在完成後再次啓用。在這裏我的代碼方法運行時禁用鍵盤

public boolean onKey(View v, int keyCode, KeyEvent event) { 
       if (event.getAction() == KeyEvent.ACTION_UP) { 
        try { 
     iKey = Integer.parseInt(eLocation.getText().toString()); 
        } catch (Exception e) { 
         eLocation.setText(""); 
         return false; 
        } 

        switch (iKey) { 
        case 1: 
         mymethod(1); 
        break; 
        case 2: 
         mymethod(2); 
        break; 
} 
+1

su?沒有?很多嗎? KOD?劈?一個? etlok?你甚至關心代碼的可讀性? – WarrenFaith

+0

su?沒有?很多嗎? KOD?劈?是其他類 – aangwi

+0

中的一種方法,它是關於命名的。如果名稱不能自我解釋,這是一種糟糕的代碼風格。不,它不算你知道它。代碼的讀取次數多於寫入次數,每個將進入項目的「外國」程序員都會遇到一個巨大的問題,以瞭解該命名風格正在發生什麼。我推薦下面這本書,它是一種代碼風格的標準:[Clean Code:敏捷軟件工匠手冊](http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882 ?tag = top10new-20) – WarrenFaith

回答

1

隱藏鍵盤使用:

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
mgr.hideSoftInputFromWindow(editText.getWindowToken(), 0); 

來說明鍵盤使用:

InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); 
// only will trigger it if no physical keyboard is open 
mgr.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT); 

如果您使用的是活動超出此代碼,改變路線爲:

InputMethodManager mgr = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE);