Delphi XE5 Android : how to make each listview item have its own template?

为君一笑 提交于 2019-11-27 07:20:02

问题


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


回答1:


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;

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;



回答2:


You will have to use TListBox, then you can add list items and each item can have item text and details but you are limited to the predefined layouts. You can not make your completely own layout like in Eclipse. You will have to use FireMonkey Style Designer to create your own style. Take a look here.



来源:https://stackoverflow.com/questions/18858965/delphi-xe5-android-how-to-make-each-listview-item-have-its-own-template

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!