Translating OnClick to OnTouch (or something similiar)?

I am new to smart phone development. I am using Delphi Xe5 to create a test application I can port to Android and IPhone.

I have a FireMonkey Mobile Application in which I have a TlistBox on the main form. I want the user to select an item in the list and I then display some information based on their selection in another form.

I currently use the ListBox's OnClick event to do this

However, when testing on devices, it seems that I have to touch it more than once (almost like a double click with a mouse).

Am I suppose to be using some kind of touch event? Gestures?

If so, how would I get the index of the selected item?

Example OnClick event

procedure TfrmProjects.lbxProjectsClick(Sender: TObject);
begin
 ShowMessage(IntToStr(lbxProjects.ItemIndex));
end;

EDIT:

I have looked at the GestureManager and tied it to the ListBox's Touch property Gesture Manager, but can't seem to find a simple OnTouch

Thanks


For TListBox , you simply use the OnChange event. There's no TGestureManager required; changes to the selection via a tap are automatically routed there:

procedure TForm1.ListBox1Change(Sender: TObject);
var
  Item: TListBoxItem;
begin
  Item := ListBox1.Selected;
  if Assigned(Item) then
    ShowMessage(Format('Item %d text is %s', [Item.Index, Item.Text]))
  else
    ShowMessage('No item selected');
end;

You might want to spend some time with the Samples that are provided for FireMonkey Mobile. (You can find them from the XE5 item in your Start menu; there's a Samples link that opens the folder.) There are two separate folders that are helpful, the FireMonkeyMobile and the MobileCodeSnippets ; both of them contain some good demo projects. There are also several tutorials in the documentation at Mobile Tutorials in the docwiki at Embarcadero.


If you find you have to tap it wice after a scroll, but not if there has been no scroll, then this is a bug I logged some while back. OnClick should work, but gets broken by a scroll operation, in my experience.

Please refer to this bug and see if it matches your experience.

Interestingly, just as an aside, there is an almost "vice versa" bug reported here.

链接地址: http://www.djcxy.com/p/50630.html

上一篇: 如何在Firemonkey Delphi XE5中更改TStringGrid的文本颜色

下一篇: 将OnClick翻译成OnTouch(或类似的东西)?