我抄Android的NumberPicker小工具,我自己的應用程序,但我有一個問題...的Android NumberPicker不節能的EditText改變
當有人手動點擊EditText上,並通過鍵盤改變了它的選擇沒有保存。是否有一些可以實現的偵聽器來檢查用戶是否手動更改EditText以將其設置爲最新?或者其他的東西?
我抄Android的NumberPicker小工具,我自己的應用程序,但我有一個問題...的Android NumberPicker不節能的EditText改變
當有人手動點擊EditText上,並通過鍵盤改變了它的選擇沒有保存。是否有一些可以實現的偵聽器來檢查用戶是否手動更改EditText以將其設置爲最新?或者其他的東西?
你可以嘗試將TextWatcher設爲您的EditText做同樣或不允許對用戶輸入的值手動那裏...
或維持OK按鈕那裏,並從取出來的值僅在用戶單擊確定按鈕時才能使用EditText
您試過這個示例嗎?
不知道,如果你使用的是相同的Numberpicker礦山:http://www.quietlycoding.com/?p=5。我試圖添加一個OnEditorActionListener到NumberClass,似乎它解決了我的問題。
實施onEditorAction:
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
validateInput(v);
return false;
}
希望能有所幫助。
我使用numberpicker http://www.quietlycoding.com/?p=5也有同樣的問題,我通過將OnKeyListener(而不是Junzi已經建議的OnEditorActionListener)添加到NumberPicker類來解決它。其他的步驟是一樣的,所以:
public boolean onKey(View v, int keyCode, KeyEvent event) {
validateInput(v);
return false;
}
我用邁克爾·諾瓦克數字選擇器。雖然onEditorAction已經實現,但沒有正確設置輸入。簡單的解決方法是在getCurrent中的textView上調用validateInput。
/**
* @return the current value.
*/
public int getCurrent() {
validateInput(mText);
return mCurrent;
}
如果從Android4.0.x使用的是Android NumberPicker意味着你可以使用的getValue得到NumberPicker的價值()。 http://developer.android.com/reference/android/widget/NumberPicker.html#getValue()
這是一個簡單的方法來獲得Numberpicker在android系統4.0.x版...
final NumberPicker np = new NumberPicker(CustomizedListView.this); np.setMinValue(0); np.setMaxValue(100); np.setWrapSelectorWheel(true);
,你可以得到使用np.getValue()方法的值。
我發現這個解決方案在Android的開發商谷歌組某處遺失:
的Android SDK NumberPicker小部件,只需使用:
myNumberPicker.clearFocus();
試圖獲取其值之前。 當你只有NumberPicker的活動,也許一個按鈕或微調,並且你編輯它並嘗試點擊其他地方,它的onFocusChangedListener處理不當。所以你只需要在使用getValue()之前強制它失去焦點。像我的魅力一樣工作。
是的,這正是我如何複製NumberPicker的方法。不幸的是,我希望用戶能夠手動輸入他們的分數。 – 2010-09-12 14:33:06
你有沒有嘗試設置一個文本觀察器到你的EditText ..?檢查這篇文章http://stackoverflow.com/questions/3665470/measure-length-of-edittext-string-dynamically-in-android/3666012#3666012 – DeRagan 2010-09-12 15:12:19