在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
转自:http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Using_ListBox_Components_to_Display_a_Table_View_(iOS_and_Android)
Go Up to Mobile Tutorials: Delphi Mobile Application Development (iOS and Android)
Using ListBox Components to Display a Table View in Mobile ApplicationsOn the mobile platform, FireMonkey uses the FMX.ListBox.TListBox component to present a Table View in a mobile style, like the following ListBoxes. Plain List
Grouped ListNote: Only iOS devices support the grouped lists.
Create Items on the ListBox Component
Add a HeaderYou can define a Header on the TListBox component by using the following steps:
Add a Group Header/Footer to the ListYou can define a Group Header and a Group Footer for items on TListBox as follows:
Show List Items as Separate Grouped ItemsItems on a ListBox can be shown as either a Plain list or a Grouped list (only for iOS target platform). This choice is controlled by the GroupingKind property and the StyleLookupproperty, as shown in the following graphic:
Important: For iOS devices, you can specify either style for your TListBox component in the Object Inspector. For Android devices, you can specify only the plain list. Add a Check Box or Other Accessory to a ListBox ItemEach item in a TListBox can use an Accessory such as Check Mark through the ItemData.Accessory property. The following picture shows the value you can assign to ItemData.Accessory and the Accessory assigned: You can select the Accessory property in the Object Inspector when ListBox Item is selected in the Form Designer. Add an Icon to a ListBox ItemEach Item on a ListBox component can contain Bitmap data, as an Icon, through the ItemData.Bitmap property: You can select the Bitmap property in the Object Inspector when the ListBoxItem is selected in the Form Designer. Add Detail Information to an ItemYou can add additional text information to each item on the ListBox component. Specify additional text in the ItemData.Detail property, and select the location of the Detail Text through the StyleLookup property, as shown in the following table:
Add Items to a ListBox from Your CodeTo add regular items to a ListBox, you can simply call the Items.Add method as following code: ListBox1.Items.Add('Text to add'); If you want to create items other than a simple item, or control other properties, you can create an instance of the item first, and then add it to the list box. The following code adds items to a ListBox, as shown in the picture:
procedure TForm40.FormCreate(Sender: TObject); var c: Char; i: Integer; Buffer: String; ListBoxItem : TListBoxItem; ListBoxGroupHeader : TListBoxGroupHeader; begin ListBox1.BeginUpdate; for c := 'a' to 'z' do begin // Add header ('A' to 'Z') to the List ListBoxGroupHeader := TListBoxGroupHeader.Create(ListBox1); ListBoxGroupHeader.Text := UpperCase(c); ListBox1.AddObject(ListBoxGroupHeader); // Add items ('a', 'aa', 'aaa', 'b', 'bb', 'bbb', 'c', ...) to the list for i := 1 to 3 do begin // StringOfChar returns a string with a specified number of repeating characters. Buffer := StringOfChar(c, i); // Simply add item // ListBox1.Items.Add(Buffer); // or, you can add items by creating an instance of TListBoxItem by yourself ListBoxItem := TListBoxItem.Create(ListBox1); ListBoxItem.Text := Buffer; // (aNone=0, aMore=1, aDetail=2, aCheckmark=3) ListBoxItem.ItemData.Accessory := TListBoxItemData.TAccessory(i); ListBox1.AddObject(ListBoxItem); end; end; ListBox1.EndUpdate; end; Add a Search BoxYou can add a search box to a ListBox. With a search box, users can easily narrow down a selection from a long list as in the following pictures:
See Also
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论