德尔福XE5 Android的:如何让每一个列表视图项有自己的模板?自己的、视图、模板、德尔福

2023-09-14 23:05:43 作者:何必作戏给我看

有没有一种方法,使德尔福的TListView的表现就像在Android的实际的ListView? 例如,列表中的每个项目都有自己的查看,并在该视图中可以有多个其他视图(组件),如多个文本框和复选框,并...?

Is there a way to make the TListView of Delphi to behave like actual ListView in android? for example each item of the list has its own "View" and in that view can be multiple other views(components) like multiple text boxes and check boxes and ...?

推荐答案

是有一种方法。余使它通过使用这两种方法。 CreateItem方法是,你把你想要的成分在ListItem。

Yes there is a way. I make it by using these two methods. The CreateItem method is where you put the components you want in the listitem.

procedure TForm1.CreateItem;
var
edit1:TClearingEdit;
editCalendar1:TCustomCalendarEdit;
begin
  edit1:= TClearingEdit.Create(Self);
  edit1.Parent := fItem;
  edit1.Align := TAlignLayout.alClient;
  edit1.Text := 'Blabla';
  edit1.OnChange := actEdit1OnChange;

  editCalendar1 := TCalendarEdit.Create(Self);
  editCalendar1.Parent := fItem;
  editCalendar1.Align := TAlignLayout.alRight;
  editCalendar1.Width := 90;
  editCalendar1.Date := Date;
  editCalendar1.OnChange := actEditCalOnChange;
end;

procedure TForm1.CreateListItem;
begin
  fItem:= TListBoxItem.Create(your_listbox);
  fItem.Parent := your_listbox; //Here you put the ListBox as a parent
  fItem.Align := TAlignLayout.alTop;
  fItem.Text := '';
  fItem.Height := 50;

  CreateItem;
end;

要自定义项添加到列表中只调用CreateListItem方法!接下来该我用的OnChange方法来这里接收的数据是一个例子:

To add a custom item to the list just call the CreateListItem method! Next to this I use the OnChange method to receive data here is an example:

procedure TForm1.actEditCalOnChange(Sender: TObject);
begin
  label1.text := TCalendarEdit(Sender).Text;
end;

procedure TForm1.actEdit1OnChange(Sender: TObject);
begin
  label2.text := TClearingEdit(Sender).Text;
end;