0

Is it possible to preform something akin to s:List.ensureIndexIsVisible(int) but scrolls to an item on the list without using its index?

In my case, I have a list of 5000+ teams. I need to be able to quickly navigate to a specific team, so on top of a search I'm implementing a system similar to iOS's UITableView Index List. The main difference between my system and that one is that mine will not have a header for each section.

At the moment, each button calls the s:List.ensureIndexIsVisible() function. However, I need to be able to jump to a specific team number, not an index. (Some teams no longer exist and therefore aren't in the list).

Is it possible to use a property of an item (the labelField, for example) to find its index? (The opposite of s:List.itemToLabel())

Here's what the app looks like:

My app so far

Matt Reynolds
  • 787
  • 2
  • 9
  • 22
  • Instead of "jumping", wouldn't it be better to implement "filtering"? You do that by setting the `filterFunction` for the `ArrayCollection` and it works well (and quick) even for Lists with many items – Alexander Farber Sep 01 '14 at 07:55
  • @Alex That would be a very good workaround, but ideally I really would like to be able to jump rather than filter. There's not much of a difference but I like the jumping behaviour better – Matt Reynolds Sep 01 '14 at 15:40

1 Answers1

0

This isn't 100% perfect, but I've cobbled together a pretty good solution. The only problem now is using the ensureIndexIsVisible function, as it doesn't necessarily put the desired index at the top of the screen. I'm probably going to work on a workaround for that too though.

Relevant Actionscript code:

protected function getItemIndexByProperty(array:ArrayCollection, property:String, value:String):int
{
    for (var i:int = 0; i < array.length; i++)
    {
        var obj:Object = Object(array[i])
        if (obj[property] == value)
            return i;
    }
    return -1;
}

protected function getNearestTeamIndex(teamnumber:int):int
{
    for (var i:int = teamnumber; i < (teamnumber+10); i++)
    {
        var result:int = getItemIndexByProperty(teamListArray,'teamnumber',i.toString());
        if (result != -1)
            return result;
    }
    return -1;
}

Relevant MXML code

<s:VGroup width="10%" height="100%" horizontalAlign="center" verticalAlign="middle" color="0x999999">
            <s:Label id="firstIndex" text="1-999" click="teamList.ensureIndexIsVisible(getNearestTeamIndex(1))"/>
            <s:Spacer height="10"/>
            <s:Label id="secondIndex" text="1000's" click="teamList.ensureIndexIsVisible(getNearestTeamIndex(1000))"/>
            <s:Spacer height="10"/>
            <s:Label id="thirdIndex" text="2000's" click="teamList.ensureIndexIsVisible(getNearestTeamIndex(2000))"/>
            <s:Spacer height="10"/>
            <s:Label id="fourthIndex" text="3000's" click="teamList.ensureIndexIsVisible(getNearestTeamIndex(3000))"/>
            <s:Spacer height="10"/>
            <s:Label id="fifthIndex" text="4000's" click="teamList.ensureIndexIsVisible(getNearestTeamIndex(4000))"/>
            <s:Spacer height="10"/>
            <s:Label id="sixthIndex" text="5000's" click="teamList.ensureIndexIsVisible(getNearestTeamIndex(5000))"/>

</s:VGroup>
Matt Reynolds
  • 787
  • 2
  • 9
  • 22
  • In regard to `ensureIndexIsVisible` usage - check this workaround: http://stackoverflow.com/questions/16044811/list-with-multilined-word-wrapping-item-renderer-how-to-scroll-to-the-bottom – Alexander Farber Sep 02 '14 at 08:01