Avoiding auto-focus to text field in string widget

Hi,

I need to modify ODK Collect so that, when a string widget is shown,
focus is not given automatically to the textfield, and the soft keyboard
does not appear, until the user explicitely taps the text field.

I've already managed to do that by commenting out these two lines of
code in StringWidget.java:

 @Override
 public void setFocus(Context context) {

     //mAnswer.requestFocus();  //THIS
     InputMethodManager inputManager =
         (InputMethodManager) 

context.getSystemService(Context.INPUT_METHOD_SERVICE);
if (!mReadOnly) {
//inputManager.showSoftInput(mAnswer, 0); //AND THIS

     } else {

inputManager.hideSoftInputFromWindow(mAnswer.getWindowToken(), 0);
}
}

It works. However, if I do so, I have the opposite problem.

Now, when the user does tap on the textfield and the keyboard appears,
it won't disappear when you change to another widget that is not a
string widget. The keyboard will stay visible until you explicitely
close it.

Why so? It is strange, because every single other kind of widget already
has a line of code that explicitely hides the soft keyboard.

I guess it is because of the way focus was given? As in: since the user
has manually given focus to the text field, only the user can hide the
keyboard?

How can I fix this?

I want the textfield to not get focus automatically (until tapped),
but when the paged is changed to another widget, I do want the keyboard
to disappear as it usually did.

Is that possible?

Thanks
m.

I think if you just don't call setFocus() it should behave as you want.

··· On Tue, Oct 18, 2011 at 12:43 PM, Matteo Sisti Sette < matteosistisette@gmail.com> wrote:

Hi,

I need to modify ODK Collect so that, when a string widget is shown, focus
is not given automatically to the textfield, and the soft keyboard does not
appear, until the user explicitely taps the text field.

I've already managed to do that by commenting out these two lines of code
in StringWidget.java:

@Override
public void setFocus(Context context) {

   //mAnswer.requestFocus();  //THIS
   InputMethodManager inputManager =
       (InputMethodManager) context.getSystemService(**

Context.INPUT_METHOD_SERVICE);
if (!mReadOnly) {
//inputManager.showSoftInput(**mAnswer, 0); //AND THIS

   } else {

inputManager.**hideSoftInputFromWindow(**mAnswer.getWindowToken(), 0);
}
}

It works. However, if I do so, I have the opposite problem.

Now, when the user does tap on the textfield and the keyboard appears, it
won't disappear when you change to another widget that is not a string
widget. The keyboard will stay visible until you explicitely close it.

Why so? It is strange, because every single other kind of widget already
has a line of code that explicitely hides the soft keyboard.

I guess it is because of the way focus was given? As in: since the user has
manually given focus to the text field, only the user can hide the keyboard?

How can I fix this?

I want the textfield to not get focus automatically (until tapped), but
when the paged is changed to another widget, I do want the keyboard to
disappear as it usually did.

Is that possible?

Thanks
m.

I think if you just don't call setFocus() it should behave as you want.

I think he can also just add android:windowSoftInputMode="stateHidden"
to the activity in the manifest if he wants that behaviour by default
for the entire activity. I might be wrong about this - I'm not sure
that it overrides setFocus().

··· On 18/10/11 02:02 PM, Carl Hartung wrote:

--
Matt Adams
Radical Dynamic

Hi, thank you for the suggestion.

However, this gives me exactly the same problem as my previous solution.
It works meaning it prevents the textfield from getting focus
automatically, but when I tap on the text and the keyboard appears, it
will never disappear.

I don't understand why the calls to
hideSoftInputFromWindow(this.getWindowToken(), 0); that are being done
from all other widgets have no effect when the focus has been set
explicitely.

Isn't the 0 as second argument supposed to mean that keyboard should be
hidden even if it was made visible explicitely by the user?

Or is it because the "window token" does not match whatever it should
match? But if so, why does it work when focus has been set via setFocus()?

Any idea?

thanks
m.

··· On 10/18/2011 10:02 PM, Carl Hartung wrote: > I think if you just don't call setFocus() it should behave as you want.