Fixed: Setting the ListPicker.selectedIndex on pageLoaded selects the correct item but it is not rendered.

This commit is contained in:
Rossen Hristov
2015-03-12 09:42:05 +02:00
parent 6d77629301
commit 388f709768
7 changed files with 99 additions and 2 deletions

View File

@@ -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([]);
}
}