Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
jmoukel
Posts: 111
Registered: ‎07-05-2012
My Device: none
Accepted Solution

BB10: ListView Items Background Problem

[ Edited ]

Hi guys,

 

 

I have a listview which items have backgrounds are of different colors (see figure). The color of each item background depends on an specific element of the item in the data model (let's say ListItemData.color). 

 

But for some reaason, when I scroll down the list and the scroll it back up, the background color changes. I don't understand this weird behaviour.

 

Do you folks have any idea about what's going on or at least how to solve it?

 

Thanks!

Developer
ekke
Posts: 1,561
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: BB10: ListView Items Background Problem

we need some code to see how you're setting the background of your items

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: BB10: ListView Items Background Problem

Usually this sort of problem comes from not understanding how ListView works under the covers. See if my explanation from this post helps you: http://supportforums.blackberry.com/t5/Cascades-Development/LstItemComponent-doesn-t-track-the-model...

Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
jmoukel
Posts: 111
Registered: ‎07-05-2012
My Device: none

Re: BB10: ListView Items Background Problem

[ Edited ]

Hi ekke,

This is how I'm setting the background of the items:

background: ListItemData.isInSalaXD ? (ListItemData.isInSalaPremier ? Color.create("#3B302C") : itemRoot.ListItem.view.getListItemBG()) : Color.create("#3A2D1F")

 Where getListItemBG() is a function that returns an ImagePaint from a ImagePaintDefinition.


Thanks.

Developer
jmoukel
Posts: 111
Registered: ‎07-05-2012
My Device: none

Re: BB10: ListView Items Background Problem

Hi peter9477,

 

I read your explanation, but I don't if what you say applies to this problem. I have the item's background linked to some of the item's data in the data model. As I show in my latest post at defining the background property.

 

Could help me please?

 

Thanks.

Developer
ekke
Posts: 1,561
Registered: ‎04-08-2010
My Device: Z10 (red Limited Edition), Q10, Z30
My Carrier: Telekom.de, O2, Vodafone

Re: BB10: ListView Items Background Problem

hmmm

ListItemData.xxxx should be ok

 

but another important point:

 

Color.create() is expensive ! you should not use it on List Items

 

you can define Colors at the Page as property:

 

property variant premiercolor: Color.create("#3B302C");

-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

BlackBerry Elite Developer
BlackBerry Platinum Enterprise Partner
International Development Mobile Apps BlackBerry 10 Cascades
Cascades - Workshops / Trainings / Bootcamps

blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner http://vimeo.com/ekkescorner/videos
bb10-development: http://appbus.org Twitter: @ekkescorner
Developer
peter9477
Posts: 6,473
Registered: ‎12-08-2010
My Device: PlayBook, Z10

Re: BB10: ListView Items Background Problem


jmoukel wrote:

Hi peter9477,

 

I read your explanation, but I don't if what you say applies to this problem. I have the item's background linked to some of the item's data in the data model. As I show in my latest post at defining the background property.

 

Could help me please?


I don't see enough information yet for me to be able to know. You say the background color changes when you scroll, but you don't describe in what way. What's it change from, and to?

 

Some of the expression includes stuff tied to the data model, yes, but at least one part of it appears not to be. I wasn't able to tell offhand whether that could be involved or not, but as I said, generally if scrolling makes things go wrong, I'd say the caching behaviour of ListView is likely involved.

 

If I were you I'd spend a bit of time characterizing the problem. Make sure the list has more than about 2.5x the number of items in total as what you can see at any one time (to ensure there's some reuse of cached items), and scroll up and down.  Change the colors as required to make it easier to analyze the problem. Try to identify a pattern with the problem... for example, is the wrong color always a particular one? Always on a particular item?  Only once you've scroll past X*2 items, where X is the visible number?


Peter Hansen -- (BB10 and dev-related blog posts at http://peterhansen.ca.)
Author of White Noise and Battery Guru for BB10 and for PlayBook | Get more from your battery!
Developer
jmoukel
Posts: 111
Registered: ‎07-05-2012
My Device: none

Re: BB10: ListView Items Background Problem

Hi all,

 

I solve it by doing this:

 

Label
{
    visible: false
    text: ListItemData.id

    onTextChange:
    {
        root.background = ListItemData.color;
    }
}

It's not elegant at all, but at least it works. The "id" member of the ListItem is the only member that's unique. So evertytime the text of this invisible label changes with the new id, it resets the background for that particular item.

 

It's a pity that I have to use this type of solution to solve this.

 

Thanks everyone!