Hi there,
there is a ListPicker in my app that contains many items. However, when the user selects an item and re-opens the ListPicker at a later time, the chosen item is not selected anymore and the list always starts with an offset of 0, so the user has to scroll all the way down and search for his previously picked item.
Is it possible to
automatically scroll the list to a certain item when opened and
highlight that item to show what the user's current choice is until he selects another item?
By the way - what's the best place to fill a ListPicker programmatically at app start? Currently I use MyList.BeforePicking() to fill a ListPicker with a list of variables. But I feel that Screen.Initialize() would be a better place, wouldn't it? The list only needs to be filled once the list items do not change afterwards.
I also tried .selectionIndex instead of .selection but this doesn't work either.
The previously chosen item is still not highlighted in the list and the list still shows up without any scroll offset, always showing the very first element.
ListPicker has no marked selection. ListView has them, but also doesn't work properly and has been repaired for a year. You won't do what you want with the standard ListPicker.
But Screen.Initialize is called once only, so this wouldn't work
BeforePicking should work according to the docs:
BeforePicking()
Event to raise when the ListPicker is clicked or the picker is shown using the Open method. This event occurs before the picker is displayed, and can be used to prepare the picker before it is shown.
BeforePicking is indeed called each time the user clicks the ListPicker to open the list. I tested this by playing a sound in the BeforePicking block. But for some reason the set .selection to is ignored.
Could this probably be a platform related issue? I am testing on Android 7.
@Patryk_F has already correctly advised you that you cannot preselect a selection programmatically for a listpicker.
You can do this with a listview, therefore consider using a listview, and program its behaviour to be like that of a listpicker. (set to empty list makes a listview disappear)