I have a sparks List with the following attributes:
verticalScrollPolicy="off"
horizontalScrollPolicy="on"
pageScrollingEnabled="true"
scrollSnappingMode="leadingEdge"
and inside is an ItemRenderer that takes up a full screen for each item. So basically it is a horizontal list that lets you swipe left and right one page at a time. Note the scrollSnappingMode is on, so the pages always snap perfectly on the page.
Also, I am setting "useVirtualLayout=true" on the Layout, so I have virtual ItemRenderers that are getting recycled.
My question is this: how do I know which ItemRenderer is currently on the screen? Is there an event or property to watch that lets me know when this page has snapped into view and is the currently visible page?
how do I know which ItemRenderer is currently on the screen?
In the situation you describe, which uses Virtual Layouts and only one element displayed on screen at a time; there will only be a single itemRenderer.
You can access the dataProvider element of the itemRenderer using the data property on your itemRenderer.
You can find the index of your data in the dataProvider using the itemIndex property on the itemRenderer.
If you want to know when the list changes from the component that contains the list; you may try listening to the change event; but I'm not sure if that will give you want you need; as it is possible to scroll without selecting a new item.
Related
I have a ListView with an ItemsSource that is a List. The viewcell binds some String properties from MyDataModel to labels as well as an ImageSource property to an Image.
The idea is they click the button, select an image from gallery, and the image in the viewcell changes to what they selected.
That all works fine, until they scroll. When the images go off screen, and you scroll back up to them then all of the images show the same image (the last one selected, or rather the first one that appears when scrolling back up).
I realize that it's unloading the image and re-loading it.. but why isn't it getting it from the correct binding source?
Not sure, if I understand your question correct (without code)...
But if you have a ListView bound to a List with a custom ViewCell and want to change some showed data, the following should work:
- first change the data in the list
- then reassign the ViewCell:
lvXX.ItemTemplate = new DataTemplate(typeof(XXyourViewCellxx));
I'm developing a dynamic ItemRenderer to edition in line for Spark DataGrid.
With the Click event on Edit button (first column), I'm refreshing the cell's row using grid.invalidateCell(x,y); inside this custom ItemRenderer, in the function prepare, I'm evaluating an 'editing' dynamic property to hide/show (.visible/.includeInLayout) the default Label or Control for edition; I'm not using actually the itemEditor DataGrid's operation, just simulating this functionality.
Everything goes well with standard spark components for edition: TextInput, ComboBox, etc, but custom components (extended from SkinnableContainer) doesn't get visible, just randomically on first row sometimes.
Is there any specific interface that custom components must implement to work inside an ItemRenderer??
The problem was this property: customComponent.includeInLayout; once you set it to false, it has problems to get visible again. I think it's bad idea to use includeInLayout inside an ItemRenderer.
Now I'm working only with .visible=(false/true) and .x coordinate.
Thanks.
I'm going insane over this issue. Basically, I have a TileList with a custom item renderer that has a TextInput in it. Let's say that the list can show 4 items at once, if there are 5 items and I edit the text on the first one, the fifth will be edited also. In general if an item is out of view, it will be change when I edit one that is showing.
Also, I had overriden the TileList class to expose the rendererArray property (so that I could access the texts on each renderer) but it will only return the renderers which are displayed.
Any help is appreciated. I need to know how to override this weird behaviour with itemrenderers that aren't currently displayed. Thanks.
Ok, if anyone runs into a similar issue, here is what you need to do:
First of all, avoid trying to iterate through the itemrenderers like I did. If you need a TextInput or another control on your TileList, make sure that these controls are bound to a property on your data object, otherwise off-screen items will have incorrect values since their itemrenderers will be recycled from the items that left the screen when you scrolled.
If you think it through, any requirement can be solved by iterating through the dataprovider instead of the itemrenderers.
Also, if you try to expose the rendererArray property like I did, notice that you will only be able to iterate through the itemrenderers that are currently displayed, since those that would belong to the items that are off-screen will not be created yet.
I hope this wasn't too confusing..
I've made a custom list itemRenderer with 2 buttons and a label. One button deletes the list entry (and thats not the problem) the second button would change the actual view.
Does anyone knows how I can change actual view within the itemrenderer ?
From what I think I understand, you want to change a viewstack or something. What you want to do is bubble an event from the itemRenderer up to a point in the display list where someone will listen and trigger an event handler which then changes the view.
So, in your itemRenderer do
dispatchEvent(new Event('someEventName', true));
And up the display list you need to listen for that even
this.addEventListener('someEventName', someHandlerFunction);
And in that function just switch your view or whatever else you want.
I'm creating a facebook application in flex.
I'm actually working on the friends component that shows your friends who are using the application. now, each friend has a profile image.
I created the component using a s:List element.
In the Skin Class of the element i configured the requestedColumnCount to 3, which means it shows 3 friends. i added buttons to scroll left and right in the list.
Whenever I scroll to see a different friend, for a half of a second i see no image because the List component is loading the image in order to view it.
is there a way to make the list preload all the elements so i won't have this kind of problem ?
You can set useVirtualLayout on the List to false, which means it will no longer "recycle" the item renderers. You may still have a lag when the item renderers initially load the images. Hope that helps.