Skip navigation
Currently Being Moderated

Calling ensureIndexIsVisible after adding items to the dataProvider

Mar 29, 2012 5:47 PM

Tags: #list #ensureindexisvisible

Hi,

 

I get a strange behavior where calling ensureIndexIsVisible doesn't show the correct item.

Am I missing the correct event to listen to after adding items to list data provider?

 

Description:

I use spark.components.List with an HorizontalLayout to display my data.

My data is displayed using ItemRenderer's.

 

After adding new items to the dataProvider I register to Event.RENDER and within this handler I call ensureIndexIsVisible and unregister to this event.

 

// adding some data to dataProvider - a few thousnd items

list.dataProvider.add(...)

 

list.addEventListener(Event.RENDER,

                                                            function renderHandler(e:Event):void

                                                            {

        // show index

        list.ensureIndexIsVisible(indexToShow);

        list.removeEventListener(Event.RENDER, renderHandler);

  });

 

Debugging I've done:

1. If I comment out removeEventListener, it will eventually work after a few times the event fires.

2. The initial location that I see is a few items behind so if i scroll a little I can find the desired item

 

Thanks,

Roy.

 
Replies

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points