• 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,这部份我有改动到源码,使它能正常辨别是点击到那一个(改动源码并不建议,有兴趣自行研究)。
  • 相关阅读:
    php中的闭包和匿名函数
    php魔术常量
    SQL查询:存在一个表而不在另一个表中的数据
    php发送http请求的几种方式
    php高级工程师面试题
    php中include、require、include_once、require_once的区别
    gitignore规则基础
    Google地图数据算法
    【营销】包子和星座
    【GPS】 数据围栏
  • 原文地址:https://www.cnblogs.com/onechen/p/4790503.html
Copyright © 2020-2023  润新知