Hello,
I want to implement the multiselection for the RadListViews in our NativeScript project. When the user holds one of the list items (LognPress), he gets into the selection-mode. From now on he should be able to select/deselect items with a normal tap, not LongPress.
I use the isItemSelected method on my RadListView-instance to check, if an item is already selected or not.
exports.onItemTap =
function
(args) {
//in selection mode...
if
(myListView.isItemSelected(myListView.getItemAtIndex(args.itemIndex))) {
myListView.deselectItemAt(args.itemIndex);
}
else
{
myListView.selectItemAt(args.itemIndex);
}
//...
};
For the first time, this scenario already works, but when I navigate to my page for a second time, the isItemSelected method returns false even though the item is selected, so I am not able to deselect an item in Tap event anymore, only with LongPress. (see the GIF in the attachment for demonstration)
This is the content of my Observable:
selectingItems:
false
,
myItems:
new
observableArrayModule.ObservableArray([]),
loadItems:
function
() {
var
self =
this
;
//first: remove old items out of the array
self.clearObservableArray(self.get(
'myItems'
));
for
(
var
i = 0; i < 30; i++) {
self.get(
'myItems'
).push({
/*some sample content...*/
});
}
},
clearObservableArray:
function
(observableArray) {
observableArray.splice(0,observableArray.length);
}
You see in my load-function, that I clear the content out of my ObservableArray with the splice method before i fill it with new content as the page is loaded.
I noticed, that I don't run into this issue, when I completely re-init my ObservableArray with self.set("myItems", new observableArrayModule.ObservableArray([])) instead, but that is not an option for me, as I have some trouble with PullToRefresh when I create a new instance of ObservableArray every time I refresh or load new content.
You can access the full source code of my code sample here: Link to sample project
The GIF in the attachment demonstrated the explained behaviour of the sample app.
My testing environment:
- NativeScript Framework version 2.3.0
- Telerik UI For NativeScript Pro version 1.4.1
Can you see what I am doing wrong? I am thankful for any advice.
Best regards