Hiding Keypad within Fragment

Lalit Jadiya

I am getting these errors when trying to hide the keyboard inside a fragment within an activity:

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);
Firass Obaid

Inside a fragment you should use getActivity(),

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

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Fragment hiding after back button

From Dev

Inappropriate Context Menu within a Fragment

From Dev

Hiding ActionBar from ActionBarActivity after a Splash Fragment

From Dev

Android - MapView within a fragment

From Dev

Trouble in Nesting a fragment within a fragment

From Dev

ListView is hiding my Fragment

From Dev

Soft keypad popsup and hides slowly in fragment and makes typing sluggish

From Dev

Homepage not hiding on Fragment visibility

From Dev

Hiding the ellipsis within an AppBar

From Dev

Hiding/Showing the toolbar when fragment in the tabs is scrolled

From Dev

Snackbar is not working within fragment class

From Dev

hiding .env file within a project

From Dev

Dock "Turn Hiding On" programmatically from within an app

From Dev

In a fragment implementation, the ListView below EditText disappears after setting keypad element (of EditText view) to hide

From Dev

Hiding toolbar and tablayout from a particular fragment in a viewpager

From Dev

Hiding of a ToolBar icon only for a specific Fragment

From Dev

hiding .env file within a project

From Dev

Change the fragment to another fragment within a setOnclick

From Dev

Replace Fragment within ListFragment

From Dev

Android - MapView within a fragment

From Dev

Textfields is hiding by the Keypad

From Dev

ListView is hiding my Fragment

From Dev

can't replace fragment within fragment

From Dev

setText within Fragment not updating

From Dev

Hiding a `Component` image within a Javascript `<Canvas>` Within an IF/ELSE statment

From Dev

Fragment over another fragment within ViewPager

From Dev

Jquery - toggleClass() is hiding the DIV but not the items within the DIV

From Dev

Viewpager within a fragment

From Dev

Fragment to fragment communication within a NavigationDrawer

Related Related

  1. 1

    Fragment hiding after back button

  2. 2

    Inappropriate Context Menu within a Fragment

  3. 3

    Hiding ActionBar from ActionBarActivity after a Splash Fragment

  4. 4

    Android - MapView within a fragment

  5. 5

    Trouble in Nesting a fragment within a fragment

  6. 6

    ListView is hiding my Fragment

  7. 7

    Soft keypad popsup and hides slowly in fragment and makes typing sluggish

  8. 8

    Homepage not hiding on Fragment visibility

  9. 9

    Hiding the ellipsis within an AppBar

  10. 10

    Hiding/Showing the toolbar when fragment in the tabs is scrolled

  11. 11

    Snackbar is not working within fragment class

  12. 12

    hiding .env file within a project

  13. 13

    Dock "Turn Hiding On" programmatically from within an app

  14. 14

    In a fragment implementation, the ListView below EditText disappears after setting keypad element (of EditText view) to hide

  15. 15

    Hiding toolbar and tablayout from a particular fragment in a viewpager

  16. 16

    Hiding of a ToolBar icon only for a specific Fragment

  17. 17

    hiding .env file within a project

  18. 18

    Change the fragment to another fragment within a setOnclick

  19. 19

    Replace Fragment within ListFragment

  20. 20

    Android - MapView within a fragment

  21. 21

    Textfields is hiding by the Keypad

  22. 22

    ListView is hiding my Fragment

  23. 23

    can't replace fragment within fragment

  24. 24

    setText within Fragment not updating

  25. 25

    Hiding a `Component` image within a Javascript `<Canvas>` Within an IF/ELSE statment

  26. 26

    Fragment over another fragment within ViewPager

  27. 27

    Jquery - toggleClass() is hiding the DIV but not the items within the DIV

  28. 28

    Viewpager within a fragment

  29. 29

    Fragment to fragment communication within a NavigationDrawer

HotTag

Archive