android - 德尔福XE5安卓: how to make each listview item have its own template?

标签 android delphi delphi-xe5

有没有办法让Delphi的TListView表现得像android中的实际ListView? 例如,列表中的每个项目都有自己的“ View ”,并且在该 View 中可以有多个其他 View (组件),例如多个文本框和复选框等等?

enter image description here

最佳答案

是的,有办法。我就是用这两种方法来实现的。 CreateItem 方法是您在列表项中放置所需组件的位置。

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 方法接收数据,这里是一个示例:

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

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

关于android - 德尔福XE5安卓: how to make each listview item have its own template?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18858965/

相关文章:

delphi - DCPCrypt安装/使用delphi 10

json - D10 到 DXE5 : what's the equivalent of TJSONBool. 创建(False)和 JSONObj.ToJSON?

android - 我什么时候应该使用 appcompat 库 android?

java - 我无法删除 geofire 关键导出处 map 上的标记

delphi - delphi中另一个单元的过程显示未声明的标识符

delphi - 为引用的命名空间创建别名

delphi - Delphi XE5编译设置中 "Limited Debugging Information"和 "Debug Information"有什么区别

Android WebView 为滚动条留出空间

android - 在 ionic 中构建 android 应用程序时如何解决问题?

multithreading - 主应用程序使用idPop3锁定以检索邮件消息(即使在线程中)