iOS: listview.getItemAtIndex is not a function

Thread is closed for posting
2 posts, 0 answers
  1. Marc
    Marc avatar
    101 posts
    Member since:
    Oct 2013

    Posted 02 Jun 2017 Link to this post


    I notice a weird issue with the ListViewEventData.

    Here is my ListView in XML:

        items="{{ favorites }}"
            <lv:ListViewLinearLayout scrollDirection="Vertical" />
               <GridLayout rows="auto" columns="*,10,auto">
                 <!-- ... -->
               <StackLayout className="separator" />


    Here is my tap event:

    exports.onItemTap = function(args) {
        var listview = args.object.parent;
        var bindingContext = args.object.bindingContext;
        var currentItem = listview.getItemAtIndex(args.itemIndex);


    The problem:

    I try to store a reference to the RadListView instance, that has triggered the tap-event. While the above code is working as expected, the app crashes on Android
     with the error message listview.getItemAtIndex is not a function.

    I noticed, that args.object.parent.parent would point to the RadListView instance on Android.

    We have a TabView with about 4-5 Tabs and each of them contains one RadListView with different data, so I don't want to apply an ID to each TabView to access it. I thought the event-arguments contain the information, which RadListView has triggered the event.

    Now I do not know if this is an already known bug or if this refers to my own code in any way.

    And when I raise the itemSelected event, then args.object points to the corresponding RadListView instance for both, Android and iOS... which is a bit confusing.


    We are working with:

    • NativeScript 2.5 (tns-core-modules 2.5.2)
    • Telerik UI for NativeScript 1.6.1


    Best regards,


  2. Nikolay Tsonev
    Nikolay Tsonev avatar
    340 posts

    Posted 05 Jun 2017 Link to this post

    Thank you for contacting us.

    I reviewed your case and indeed the parent property will return a reference to different objects while using the property on Android and iOS. This issue a valid problem also in the new version 2.0.1 and it has been already reported in this issue in nativescript-ui-feedback repository. 

    With the upcoming release 3.0.0, args.object property will refer to the RadListView and there will be no need top access the component while using parent 
    Also, this problem has been already fixed and you could test it on your side while using our @next tag.
    tns plugin remove nativescript-telerik-ui-pro
    tns plugin add nativescript-telerik-ui-pro

    If this is not applicable for you, meanwhile, you could use the platform module and check about the platform type. In this case, you will able to get the Listview by using args.object.parent.parent and for iOS - args.object.parent. For example:

    var platform_1 = require("platform");
    function onPageLoaded(args) {
        var page = args.object;
        page.bindingContext = new viewModel.ViewModel();
    exports.onPageLoaded = onPageLoaded;
    function onItemTap(args) {
        var listview;
        if (platform_1.isAndroid) {
            listview = args.object.parent.parent;
        else {
            listview = args.object.parent;
    exports.onItemTap = onItemTap;

    Hope this will help.
    Progress Telerik
    Did you know that you can open private support tickets which are reviewed and answered within 24h by the same team who built the components? This is available in our UI for NativeScript Pro + Support offering.
Back to Top