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
Contributor
raspberry1
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU
Accepted Solution

Changing background color for a selected item in a ListView?

Hi,

 

 Any idea how to change tbackground color of a ListView selected item from blue to a another color?

 

 I tried wrapping the ListView in a Container then changing the background color of the container, but that did not work. And neither the ListView nor the ListItemComponent takes a background attribute.

 

 

Thanks,

Please use plain text.
Developer
shreyansjain
Posts: 141
Registered: ‎07-03-2013
My Device: BB 9360
My Carrier: WIND

Re: Changing background color for a selected item in a ListView?

Ah, I did that last night. 
So, in the container for StandardItem, add this line:

 background: ListItem.selected || ListItem.active ? Color.create("#4D9EC9") : Color.Transparent

 and onTriggerred signal, add couple lines:

// for highlighting
listView.select(indexPath, true);
                           
// for clearing highlight
listView.clearSelection();

PS: listView is the id of the ListView

ListView {
    id: listView
....

 

 

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

Re: Changing background color for a selected item in a ListView?

hint: Color.create is expensive

 

so its recommended to it this way

Page {
id: myPage
property variant selectionColor: Color.create("#4D9EC9")

and then

 

background: ListItem.selected || ListItem.active ? myPage.selectionColor : Color.Transparent
-------------------------------------------------------------------------------
ekke (independent software architect, rosenheim, germany)

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

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Contributor
raspberry1
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU

Re: Changing background color for a selected item in a ListView?

Thank you all, the selection color is now changed.

 

Another quick one, how now to change the grouping line color. I have my DataGroupModel (inside the ListView) doing grouping based on the first charcter of the contact, so in when the page is rendered in the ListView contacts are grouped properly, but with the default line separator in Blue, I also would like to change this color as well, how possible?

 

Thanks again,

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

Re: Changing background color for a selected item in a ListView?

you should open a new thread for a new question

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

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

Open Source Enthusiast
blog: http://ekkes-corner.org videos: http://www.youtube.com/user/ekkescorner
bb10-development: http://appbus.org Twitter: @ekkescorner
Please use plain text.
Contributor
raspberry1
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU

Re: Changing background color for a selected item in a ListView?

Sure, will do that. 

 

Thanks,

Please use plain text.