Those arguments are FLAGS.  Specifying 0 (none of the flags) gives you the
default behavior, which for hiding is "always".  The flags are used to limit
when it hides to certain situations.  If you just want to force the keyboard
to close, use hideSoftInputFromWindow(view.getWindowToken(), 0).

The long press on menu is implemented by just doing
toggleSoftInput(view.getWindowToken(), InputMethodManager.SHOW_FORCED, 0);

You probably don't want to use SHOW_FORCED yourself (this is why it isn't
the default) because that will leave the IME displayed when the user moves
to another activity (even in another application), mostly regardless of what
that application's default preference is.

Note also:

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#hideSoftInputFromWindow(android.os.IBinder,%20int,%20android.os.ResultReceiver)

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#showSoftInput(android.view.View,%20int,%20android.os.ResultReceiver)

http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html#isFullscreenMode()

On Thu, Sep 24, 2009 at 10:14 PM, James W <jpbwebs...@gmail.com> wrote:

>
> Dwass, dont know if this helps, but I finally got it to work reliably
> for my particular needs.
>
> I have a dialog with a single edit, and I wanted to softkeyboard to
> automatically show when the dialog was opened, and be closed when the
> dialog was closed. In other words, identical behaviour to the
> EditTextPreference when used in a PreferenceScreen.
>
> In my OnCreate() I have:
>
>                InputMethodManager imm = (InputMethodManager)
> SingleEditDialog.this.getContext().getSystemService
> (Context.INPUT_METHOD_SERVICE);
>                imm.toggleSoftInput
> (InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);
>
> Which shows the keyboard when the dialog is opened. Like you, I had
> trouble getting the thing to hide when I close the dialog, I tried
> calling toggleSoftInput again but no amount of changing the settings
> seems to work. It is not entirely clear what is going on here, and I
> am not sure why there is not a .HIDE_FORCED option. It is my app, why
> can't I control when the keyboard is shown?
>
> In the end, as I only had one edit field, I was able to use another
> method to hide it,
>
>        imm.hideSoftInputFromWindow(singleedittext.getWindowToken(),
> 0);
>
> where singleedittext is my EditText view.
>
> Incidentally, there doesn't appear to be a corresponding
> showSoftInputForWindow() call, though, which is again odd.
>
> Anyway, it now works perfectly. Hope this helps someone else!
>
>
>
> On Sep 22, 4:06 pm, dwass <dw...@sharpmind.de> wrote:
> > Hi Dianne,
> >
> > You say that the G1 has akeyboardand so the IME is not shown by
> > default. I don't understand that statement. Yes, the G1 has akeyboard,
> but it isn't always OPEN. Especially if the device is in
> > portrait mode, thekeyboardis probably NEVER open. The device should
> > be smart enough so that it opens thekeyboardif there is nokeyboard
> > open. Either that, or we need a way to show thekeyboardwhen we want
> > to (and hide it again when we don't).
> >
> > My current problem is this: When I start an activity, the first
> > EditText field in the layout is focused automatically, but the
> softkeyboardis not automatically shown. The user must either click (with
> > trackball) or touch the field to open the softkeyboard. IMHO the
> > developer should be able to say that he wants thekeyboardshown at
> > this point.
> >
> > Any suggestions? I've tried all the "force showkeyboard" suggestions
> > and they sometimes do work, but usually you get stuck with
> thekeyboardbeing shown after you leave the field and this causes more
> > problems that it solves.
> >
> > Thanks,
> > -DWass
> >
> >
> >
> > > On Sep 19, 8:42 am, Dianne Hackborn <hack...@android.com> wrote:
> >
> > > > The G1 has akeyboard, so it works as I said -- the IME is not shown
> by
> > > > default.  This is a policy decision of the platform.
> >
> > > > On a myTouch, since it doesn't have akeyboard, the IME will be shown
> by
> > > > default in various cases (for example when you enter the edit
> contacts
> > > > screen) when the app has indicated that is desired with the input
> options.
> >
> > > > --
> > > > Dianne Hackborn
> > > > Android framework engineer- Hide quoted text -
> >
> > - Show quoted text -
> >
>


-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to