2015-06-17 12 views
6

sto ottenendo questi errori quando si cerca di nascondere la tastiera all'interno di un frammento all'interno di un'attività:Nascondere tastiera all'interno di 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); 

risposta

10

All'interno di un frammento si dovrebbe usare getActivity(),

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

Ancora Errore: Impossibile risolvere Contesto –

+0

Risolto Funziona Grande Fira –

+0

ottimo, contrassegnarlo come risposta corretta;) –

Problemi correlati