This is a migrated thread and some comments may be shown as answers.

Getting the currently visible itemIndex

3 Answers 262 Views
ListView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
NathanaelA
Top achievements
Rank 1
NathanaelA asked on 09 Nov 2016, 11:42 PM

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?

 

3 Answers, 1 is accepted

Sort by
0
Nick Iliev
Telerik team
answered on 10 Nov 2016, 09:02 AM
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
0
NathanaelA
Top achievements
Rank 1
answered on 10 Nov 2016, 09:59 AM

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. 

0
Nick Iliev
Telerik team
answered on 10 Nov 2016, 11:42 AM
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 - 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
Tags
ListView
Asked by
NathanaelA
Top achievements
Rank 1
Answers by
Nick Iliev
Telerik team
NathanaelA
Top achievements
Rank 1
Share this question
or