Skip to content Skip to sidebar Skip to footer

How To Change Properties Of A Tlistboxitem In A Android App In Runtime?

In my program, i made a function which reads a xml of a blog and put the Titles in a TListBox. But i need to change some properties in TListBoxItem, like font, height and color, bu

Solution 1:

[Tested with Delphi-XE7] At runtime, Listboxitems already have a calculated style stored in : aListboxItem.StyledSettings. To change a setting at runtime, you first have to remove it from the list of styled settings.

For example, if you want to change the FontColor, first remove the styled fontcolor:

aListboxItem.StyledSettings := aListboxItem.StyledSettings - [TStyledSetting.FontColor];

Then apply another one (let's say Green):

aListboxItem.FontColor := TAlphaColors.Green;

The TStyledSetting constants and corresponding TTextSettings properties are listed here in Delphi's doc.

Examples for changing styles at runtime can be found here and there.

Nota Bene: theListBox.Items[i] gives access to item content, not the item itself. To grab a ListboxItem as a control, and then act on its properties, you can use:

aListboxItem := theListBox.ListItems[i];

or

aListboxItem := theListBox.ItemByIndex(i);

Both giving exactly the same result, I cannot say if one is better.

Post a Comment for "How To Change Properties Of A Tlistboxitem In A Android App In Runtime?"