Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NumberPicker not saving EditText changes

I have copied Android's NumberPicker widget to my own application, but I'm having one problem...

When someone manually clicks the EditText and changes it via the keyboard, the selection is not saved. Is there some listener that I can implement to check and see if the user manually changes the EditText to set it as current? Or something?

like image 814
Fran Fitzpatrick Avatar asked Sep 11 '10 13:09

Fran Fitzpatrick


2 Answers

I found this solution lost somewhere in android-developers google group:

For android SDK NumberPicker widget, simply use:

myNumberPicker.clearFocus();

before you try to get its value. When you have an activity with only the NumberPicker and maybe a button or a spinner, and you edit it and try to click elsewhere, its onFocusChangedListener is not handled properly. So you just need to force it to lost focus before using getValue(). Worked like a charm to me.

like image 153
Dvd Franco Avatar answered Sep 28 '22 02:09

Dvd Franco


I used the Michael Novak number picker. Although onEditorAction was already implemented it didn't properly set the input. The easy fix for me was to call validateInput on the textView in getCurrent.

/**
 * @return the current value.
 */
public int getCurrent() {
    validateInput(mText);
    return mCurrent;
}
like image 42
HannahMitt Avatar answered Sep 28 '22 03:09

HannahMitt