Firemonkey ListView 点击事件

Firemonkey ListView 的点击事件一直让人摸不着头绪(各平台触发规则不太相同),因为它提供了点击相关的事件就有如下:

  • OnChange:改变项目触发。
  • OnClick:点击触发。
  • OnItemClick:点击项目触发
    • Windows 平台:按下立即触发,放开后接着触发 OnItemClickEx。
    • Android 平台:按下立即触发,不用放开接着 OnItemClickEx(按钮 Button 触发顺序与 Widnows 相同,要放开才会触发 OnItemClickEx)。
  • 下列以这二个事件为例:
    • OnItemClickEx:项目内单项触发。
    • OnButtonClick:按钮事件。

下例将 Item.Apperance 设定为 Custom。

 

可获取每一个单项的事件触发:

 

参考代码:

procedure TForm1.ListView1ItemClickEx(const Sender: TObject; ItemIndex: Integer;
  const [Ref] LocalClickPos: TPointF; const ItemObject: TListItemDrawable);
begin
     if ItemObject is TListItemText       then Label1.Text := 'OnItemClickEx_Text_'      + ItemIndex.ToString else
     if ItemObject is TListItemImage      then Label1.Text := 'OnItemClickEx_Image_'     + ItemIndex.ToString else
     if ItemObject is TListItemAccessory  then Label1.Text := 'OnItemClickEx_Accessory_' + ItemIndex.ToString;
end;

procedure TForm1.ListView1ButtonClick(const Sender: TObject;
  const AItem: TListItem; const AObject: TListItemSimpleControl);
begin
     if AObject is TListItemGlyphButton then Label1.Text := 'OnButtonClick_GlyphButton_' + AItem.Index.ToString else
     if AObject is TListItemTextButton  then Label1.Text := 'OnButtonClick_TextButton_'  + AItem.Index.ToString;
end;

 

有一些问题存在:

  1. 点击 Accessory 后是触发 Text 而非 Accessory,这部份我有改动到源码,使它能正常辨别是点击到那一个(改动源码并不建议,有兴趣自行研究)。

 

posted @ 2015-09-08 07:27  龟山Aone  阅读(3324)  评论(0编辑  收藏  举报