mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Fixed: Setting the ListPicker.selectedIndex on pageLoaded selects the correct item but it is not rendered.
This commit is contained in:
@@ -56,6 +56,7 @@ export class ListPicker extends common.ListPicker {
|
||||
},
|
||||
|
||||
format: function (index: number) {
|
||||
console.log("format(" + index + ")");
|
||||
if (this.owner) {
|
||||
return this.owner._getItemAsString(index);
|
||||
}
|
||||
@@ -70,10 +71,22 @@ export class ListPicker extends common.ListPicker {
|
||||
},
|
||||
|
||||
onValueChange: function (picker: android.widget.NumberPicker, oldVal: number, newVal: number) {
|
||||
console.log("onValueChange("+oldVal+", "+newVal+")");
|
||||
if (this.owner) {
|
||||
this.owner._onPropertyChangedFromNative(common.ListPicker.selectedIndexProperty, newVal);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
this._fixDisappearingSelectedItem();
|
||||
}
|
||||
|
||||
private _fixDisappearingSelectedItem() {
|
||||
//HACK: http://stackoverflow.com/questions/17708325/android-numberpicker-with-formatter-does-not-format-on-first-rendering/26797732
|
||||
//dgel's solution doesn't work for me: when I tap on the picker, formatting disappears again.This bug is caused by input filter set on EditText inside NumberPicker when setDisplayValues isn't used. So I came up with this workaround:
|
||||
var mInputTextField = java.lang.Class.forName("android.widget.NumberPicker").getDeclaredField("mInputText");
|
||||
mInputTextField.setAccessible(true);
|
||||
var mInputText = <android.widget.EditText>mInputTextField.get(this._android);
|
||||
mInputText.setFilters([]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user