Getting the currently visible itemIndex

4 posts, 0 answers
  1. NathanaelA
    NathanaelA avatar
    4 posts
    Member since:
    Apr 2015

    Posted 09 Nov Link to this post

    The normal getFirstVisiblePosition on a list view does not work on the RLV, how exactly can I get the currently displayed position so I can reset it back?

     

  2. Nikolay Iliev
    Admin
    Nikolay Iliev avatar
    92 posts

    Posted 10 Nov Link to this post

    Hello Nathanael,

    Can you give us additional information on what your specific scenario is and what you want to achieve?

    Indeed, you can't use getItemAtPostition() with RadLiastView.
    However, there are possible workarounds in order to keep track on the last interacted item and load back to this position in the list.(if that is the desired behavior).

    For example, you can "cache" the item that the user has interacted with and then scroll back to this specific index.
    export function onItemTap(args:RadListwModule.ListViewEventData) {
        var tappedItemIndex = args.itemIndex;
        roversViewModel.set("cachedIndex", tappedItemIndex);
          
        // more onItemTap logic  follows here..
    }

    And then scroll the list to this specific item when the user navigates back to it.
    export function onListLoaded(args: RadListwModule.ListViewEventData) {
        list = <RadListwModule.RadListView>args.object;
     
        if (list.items) {
            list.scrollToIndex(roversViewModel.get("cachedIndex"));
        }
    }

    If itemTap is not the event you are looking for the, perhaps, you can use the itemSelected events again with combination with a view model to "cache" the last selected item.
    For more information about handling the selected states, you can take a look at this documentation section.

    Regards,
    Nikolay Iliev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. NathanaelA
    NathanaelA avatar
    4 posts
    Member since:
    Apr 2015

    Posted 10 Nov in reply to Nikolay Iliev Link to this post

    That is an interesting way to try to do it; however if the person flicks even slightly the listview; the index is going to be wildly out of range.

    Any other ideas on how to get the Actual index of the current item showing?    Can we drop a enhancement request for this?

    The issue is really what you are talking about; saving the current location navigating to another page; and then returning I want to position the listview as close to before as possible...    However, I have no access to the itemSelected event as they might hit one of any number of buttons in the listview item, and so those directly catch the event and don't pass it on to the listview for it to fire the selection event on Android. 

  4. Nikolay Iliev
    Admin
    Nikolay Iliev avatar
    92 posts

    Posted 10 Nov Link to this post

    Hi Nathanael,

    I see your point - indeed, it is a good idea to expose method similar to getFirstVisiblePosition for
    such cases where the user may not go through the itemTap but you will still need a reliable way to track the visible position of the scrolled list.
    I have logged your feature request here where you can track it and discuss it with the telerik-ui developer team.

    Meanwhile, you can see how I have implemented the tracking here (although my case is pretty simple and I am resetting the whole list-view model upon navigating)

    Regards,
    Nikolay Iliev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top