2015-06-17 10 views
6

ja się tych błędów, próbując ukryć klawiaturę wewnątrz fragmentu w ramach działania:Ukrywanie klawiatury ciągu Fragment

Error: Cannot resolve getSystemService

Cannot resolve Context

Cannot resolve getCurrentFocus()

InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); 
inputManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 
InputMethodManager.HIDE_NOT_ALWAYS); 

Odpowiedz

10

Wewnątrz fragmentu należy użyć getActivity()

 InputMethodManager inputManager = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); 
    inputManager.hideSoftInputFromWindow(getActivity().getCurrentFocus().getWindowToken(), 
      InputMethodManager.HIDE_NOT_ALWAYS); 
+1

Wciąż błąd: nie można rozwiązać kontekstu –

+0

Załatwione działa Wielkie Firass –

+0

świetnie, proszę oznaczyć je jako poprawną odpowiedź;) –

Powiązane problemy