如何更改TlistBoxItem的性能在运行时Android应用? [英] How to change properties of a TlistBoxItem in a android app in runtime?

查看:230
本文介绍了如何更改TlistBoxItem的性能在运行时Android应用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的计划,我犯了一个函数读取博客的XML,并把标题在的TListBox 。但我需要改变 TListBoxItem 一些属性,如字体,高度和颜色,但它不会改变。

如何设置它在运行时?

 重复
  标题:= ANode.ChildNodes ['标题']文本;
  友情链接:= ANode.ChildNodes ['链接']文本;
  说明:= ANode.ChildNodes ['说明']文本;
  DataPub:= ANode.ChildNodes ['pubdate的']文本;
  SetLength函数(Vet_News,波什+ 1);
  Vet_Nesw [名次] ='< H2>'+标题+'< / H>'+说明;
  Itemx:= TListBoxItem.Create(个体经营);
  Itemx.Text:=标题;
  Itemx.ItemData.Detail:= DataPub;
  Itemx.ItemData.accessory:= TListBoxItemData.TAccessory.aMore;
  Itemx.TextSettings.WordWrap:=真;
  Itemx.TextSettings.FontColor:= TAlphaColorRec.Darkorange;
  Itemx.Height:= 65;
  Itemx.FontColor:= TAlphaColorRec.Darkorange; //我试图通过两条途径来改变颜色
  lbNews.AddObject(Itemx); // lbnews是一个TListBox
  公司(POS);
  阳极:= ANode.NextSibling;
直到阳极=零;


解决方案

[用Delphi-XE7测试]
在运行时,Listboxitems已经存储在计算风格: aListboxItem.StyledSettings
在运行时改变设置,您必须首先从样式设置列表中删除。

例如,如果要修改 FONTCOLOR ,先卸下风格FONTCOLOR:

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

然后申请另一个(比方说绿色):

  aListboxItem.FontColor:= TAlphaColors.Green;

TStyledSetting 常量和相应的 TTextSettings 属性列的 nofollow的>在这里。

在运行时改变风格的例子可以发现 rel=\"nofollow\">和的的。

诺塔Bene的: theListBox.Items [I] 可访问项目内容,而不是项目本身。
为了抢一个ListBoxItem的作为对照,然后在其属性的行为,你可以使用:

  aListboxItem:= theListBox.ListItems [I]

  aListboxItem:= theListBox.ItemByIndex(I)

这两个给完全相同的结果,我不能说,如果一个更好。

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, but it doesn't change.

How to set it in runtime ?

repeat
  Title := ANode.ChildNodes['title'].Text;
  Link := ANode.ChildNodes['link'].Text;
  Desc := ANode.ChildNodes['description'].Text;
  DataPub := ANode.ChildNodes['pubDate'].Text;
  SetLength(Vet_News, Pos + 1);
  Vet_Nesw[Pos] := '<h2>'+Title+'</h2>'+Desc;
  Itemx := TListBoxItem.Create(self);
  Itemx.Text := Title;
  Itemx.ItemData.Detail := DataPub;
  Itemx.ItemData.accessory := TListBoxItemData.TAccessory.aMore;
  Itemx.TextSettings.WordWrap := true;
  Itemx.TextSettings.FontColor := TAlphaColorRec.Darkorange;
  Itemx.Height := 65;
  Itemx.FontColor := TAlphaColorRec.Darkorange; // i tried two ways to change the color
  lbNews.AddObject(Itemx); // lbnews is a Tlistbox 
  Inc(Pos);
  ANode := ANode.NextSibling;
until ANode = nil;

解决方案

[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.

这篇关于如何更改TlistBoxItem的性能在运行时Android应用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆