<small id='1C3dK'></small><noframes id='1C3dK'>

<i id='1C3dK'><tr id='1C3dK'><dt id='1C3dK'><q id='1C3dK'><span id='1C3dK'><b id='1C3dK'><form id='1C3dK'><ins id='1C3dK'></ins><ul id='1C3dK'></ul><sub id='1C3dK'></sub></form><legend id='1C3dK'></legend><bdo id='1C3dK'><pre id='1C3dK'><center id='1C3dK'></center></pre></bdo></b><th id='1C3dK'></th></span></q></dt></tr></i><div id='1C3dK'><tfoot id='1C3dK'></tfoot><dl id='1C3dK'><fieldset id='1C3dK'></fieldset></dl></div>
    • <bdo id='1C3dK'></bdo><ul id='1C3dK'></ul>

      <legend id='1C3dK'><style id='1C3dK'><dir id='1C3dK'><q id='1C3dK'></q></dir></style></legend>

        <tfoot id='1C3dK'></tfoot>
      1. 在 Firemonkey 中滚动后,ListBox 项目发生变化

        时间:2023-05-19
        <i id='4b9Eo'><tr id='4b9Eo'><dt id='4b9Eo'><q id='4b9Eo'><span id='4b9Eo'><b id='4b9Eo'><form id='4b9Eo'><ins id='4b9Eo'></ins><ul id='4b9Eo'></ul><sub id='4b9Eo'></sub></form><legend id='4b9Eo'></legend><bdo id='4b9Eo'><pre id='4b9Eo'><center id='4b9Eo'></center></pre></bdo></b><th id='4b9Eo'></th></span></q></dt></tr></i><div id='4b9Eo'><tfoot id='4b9Eo'></tfoot><dl id='4b9Eo'><fieldset id='4b9Eo'></fieldset></dl></div>

        <legend id='4b9Eo'><style id='4b9Eo'><dir id='4b9Eo'><q id='4b9Eo'></q></dir></style></legend>

              <bdo id='4b9Eo'></bdo><ul id='4b9Eo'></ul>

              <small id='4b9Eo'></small><noframes id='4b9Eo'>

              1. <tfoot id='4b9Eo'></tfoot>

                  <tbody id='4b9Eo'></tbody>

                  本文介绍了在 Firemonkey 中滚动后,ListBox 项目发生变化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我正在 Firemonkey 中开发一个多设备应用程序,其中 Main 类有一个带有一些项目的 ListBox 组件.这些项目中的每一个都具有相同的自定义样式.

                  I am developing a Multi-Device Application in Firemonkey where Main class has a ListBox component with some items. Each of these items has the same custom style.

                  我的问题是当我在 ListBox 中有这么多项目时,我必须垂直滚动才能看到其余项目.在这种情况下,ListBox 有一个奇怪的行为,当我在向下滚动后向上滚动时,项目的组件(例如按钮)已经改变了他的背景颜色并且项目已经改变了他在 ListBox 中的顺序.

                  My problem is when I have so many items in the ListBox and I have to do scroll vertical to see the rest of items. In this case, the ListBox has a strange behaviour and when I do scroll up after doing scroll down the item's components (a button for example) have changed his background colour and the items have changed his order inside ListBox.

                  例如,如果我有:

                  1. 第 1 项
                  2. 第 2 项
                  3. 第 3 项

                  滚动后我有:

                  1. 第 2 项
                  2. 第 3 项
                  3. 第 1 项

                  这种变化是随机的.每次都不一样.

                  This change is random. Each time is different.

                  实例(流程步骤):

                  1. 加载 ListBox 所在的 Main 类.

                  1. 垂直向下滚动以查看其余项目.

                  1. Do vertical scrolling down to see the rest of items.

                  向上垂直滚动以返回列表顶部.

                  Do vertical scrolling upward to return to the top of the list.

                  1. 项目在 ListBox 中的位置发生了变化,并且按钮(每个项目的组件)改变了它的背景颜色.

                  为什么我在 ListBox 中有这种行为?我该如何解决它并且 ListBox 不改变项目顺序也不改变其组件的背景颜色?

                  Why I have this behaviour in the ListBox?? How I can solve it and the ListBox do not change items order neither background colour of his components?

                  我不知道是否有任何属性可以阻止 ListBox 或类似内容中的项目...

                  I do not know if there is any property to block items inside ListBox or similar ...

                  编辑

                  这是创建和初始化 ListBox 项的代码:

                  This is the code to create and initialize the ListBox items:

                  procedure TRooms_Form.FormCreate(Sender: TObject);
                  var
                    ...
                  begin
                      i := 0;
                      while i < numItems do begin
                        //Create ListBox item
                         item := TListBoxItem.Create(nil);
                         item.Parent := myListBox;
                         item.StyleLookup := 'styleLBox';
                        //Number
                         itemNumber := item.FindStyleResource('btt_number') as TButton;
                         if Assigned(itemNumber) then begin
                             itemNumber.Text := jsonNumber;
                             case jsonColor of
                               0 : itemNumber.TintObject.TintColor := TAlphaColors.Chocolate; 
                               1 : itemNumber.TintObject.TintColor := TAlphaColors.Gold;      
                               2 : itemNumber.TintObject.TintColor := TAlphaColors.Darkgreen; 
                               3 : itemNumber.TintObject.TintColor := TAlphaColors.Deeppink;  
                             end;
                           end;
                        //Title
                         itemTitle := item.FindStyleResource('txtstyle_title') as TText;
                         if Assigned(itemTitle) then begin
                           itemTitle.Text := jsonTitle;
                         end;
                        //Occupation
                         itemOccup := item.FindStyleResource('txt_occupation') as TText;
                         if Assigned(itemOccup) then begin
                           itemOccup.Text := jsonOccup;
                         end;
                        //Dates
                         itemDay := item.FindStyleResource('txt_day') as TText;
                         if Assigned(itemDay) then itemDay.Text := displayDay;
                         itemDateStart := item.FindStyleResource('txt_start') as TText;
                         if Assigned(itemDateStart) then itemDateStart.Text := jsonTimeStart;
                         itemDateEnd := item.FindStyleResource('txt_end') as TText;
                         if Assigned(itemDateEnd) then itemDateEnd.Text := jsonTimeEnd;
                        //Item background
                         itemBackgr := item.FindStyleResource('background_item') as TRectangle;
                         if Assigned(itemBackgr) then begin
                           itemBackgr.Fill.Kind := TBrushKind.Solid;
                           case jsonStatus of
                             0 : itemBackgr.Fill.Color := TAlphaColors.White;         
                             1 : itemBackgr.Fill.Color := TAlphaColors.Lightgreen;    
                             2 : itemBackgr.Fill.Color := TAlphaColors.Palegoldenrod; 
                             3 : itemBackgr.Fill.Color := TAlphaColors.Lightcoral;    
                             4 : itemBackgr.Fill.Color := TAlphaColors.Lightseagreen; 
                             5 : itemBackgr.Fill.Color := TAlphaColors.Lightblue;     
                             6 : itemBackgr.Fill.Color := TAlphaColors.Lightgrey;     
                           end;
                         end;
                        //Empty item
                         if (StrToInt(jsonEmpty) = 1) or (StrToInt(jsonNull) = 1) then begin
                           startDetail[i] := False;
                           if Assigned(itemNumber) then itemNumber.Visible := False;
                           if Assigned(itemOccup) then itemOccup.Visible := False;
                         end
                         else begin
                           startDetail[i] := True;
                         end;
                  
                         Inc(i);
                      end;
                  

                  非常感谢您的关注.

                  推荐答案

                  经过几天和一些测试,我已经找到了解决问题的方法.

                  After some days and some tests, I have already found a solution to my problem.

                  我不太明白为什么,但有一些代码行干扰了我的自定义样式.

                  I do not understand well why but there was some code lines that they were interfering with my custom style.

                  例如,当我输入:

                  //Item background
                     itemBackgr := item.FindStyleResource('background_item') as TRectangle;
                     if Assigned(itemBackgr) then begin
                       **itemBackgr.Fill.Kind := TBrushKind.Solid;**
                       ...
                  

                  滚动后,项目更改了订单位置及其颜色背景.我已经在自定义样式的TRectangle"组件中直接应用了这个属性.

                  After scroll, items changed order position and their color background. I have applied this property directly in the 'TRectangle' component in the custom style.

                  另外,我把所有元素的分配改成这样:

                  Moreover, I changed the allocation of all elements to this way:

                  -之前我有:

                     itemTitle := item.FindStyleResource('txtstyle_title') as TText;
                     if Assigned(itemTitle) then begin
                       itemTitle.Text := jsonTitle;
                     end;
                  

                  -现在,我有:

                     item.StylesData['txtstyle_title'] := jsonTitle;
                  

                  通过这些更改,我得到的项目在滚动后不会改变它们在 ListBox 中的位置,也不会改变背景颜色.

                  With these changes I get items do not change their position in ListBox neither background color after scroll.

                  我遇到了一个问题,按钮没有显示它们的背景颜色,这是由于这些行:

                  I had a problem yet, buttons do not show their background color and it was due to these lines:

                  //Empty item
                     if (StrToInt(jsonEmpty) = 1) or (StrToInt(jsonNull) = 1) then begin
                       startDetail[i] := False;
                       **if Assigned(itemNumber) then itemNumber.Visible := False;**
                       **if Assigned(itemOccup) then itemOccup.Visible := False;**
                     end
                     else begin
                       startDetail[i] := True;
                     end;
                  

                  显然,您无法在FormCreate"方法中更改项目的可见属性,因为当您滚动某些项目时,某些元素会在不受控制的情况下更改其属性.因此,我对我的代码进行了一些修改,而不是将可见性设置为 false:

                  Apparently, you cannot change visible property from item in 'FormCreate' method because when you do scroll some items elements change their property without control. Therefore, I have done some modifications in my code instead of putting to false the visibility:

                      if (StrToInt(jsonEmpty) = 1) or (StrToInt(jsonNull) = 1) then begin
                        startDetail[i] := False;
                        item.StylesData['btt_number.Text'] := '';
                        item.StylesData['txt_occupation'] := '';
                        if (StrToInt(jsonEmpty) = 1) then item.StylesData['btt_number.TintObject.TintColor'] := TAlphaColors.White;
                        if (StrToInt(jsonNull) = 1) then item.StylesData['btt_number.TintObject.TintColor'] := TAlphaColors.Lightblue;
                      end
                      else begin
                        startDetail[i] := True;
                        item.StylesData['btt_number.Text'] := jsonNumber;
                        item.StylesData['txt_occupation'] := jsonOccup;
                      end;
                  

                  在这个表单中,我将文本''(空)和背景颜色放在与他的项目(TRectangle)相同的颜色中,该元素应该具有可见属性为false.

                  At this form, I put the text ' ' (empty) and the background color at the same color that his item (TRectangle) in the elements who should to have the visible property to false.

                  在所有这些更改之后,我得到了我想要的结果,也就是说,我的项目 ListBox 在我滚动时不会改变.呵呵

                  After all these changes I get the result that I wanted, that is to say, my items ListBox do not change when I scroll. XD

                  这篇关于在 Firemonkey 中滚动后,ListBox 项目发生变化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Android Activity 垃圾收集 下一篇:无法将使用 JVM 目标 1.8 构建的字节码内联到使用 JVM 目标 1.6 构建的字节码

                  相关文章

                    <bdo id='I7R49'></bdo><ul id='I7R49'></ul>
                  <tfoot id='I7R49'></tfoot>

                      <legend id='I7R49'><style id='I7R49'><dir id='I7R49'><q id='I7R49'></q></dir></style></legend>

                    1. <i id='I7R49'><tr id='I7R49'><dt id='I7R49'><q id='I7R49'><span id='I7R49'><b id='I7R49'><form id='I7R49'><ins id='I7R49'></ins><ul id='I7R49'></ul><sub id='I7R49'></sub></form><legend id='I7R49'></legend><bdo id='I7R49'><pre id='I7R49'><center id='I7R49'></center></pre></bdo></b><th id='I7R49'></th></span></q></dt></tr></i><div id='I7R49'><tfoot id='I7R49'></tfoot><dl id='I7R49'><fieldset id='I7R49'></fieldset></dl></div>

                      <small id='I7R49'></small><noframes id='I7R49'>