how to detect event tap on specific image

android nativescript gesture nativescript-telerik-ui

49 观看

1回复

19 作者的声誉

var gestures = require("ui/gestures");

for (var i = 0; i < images.length; i++) {
      imgArray[i] = new imageModule.Image();
  imgArray[i].id = "img";
  imgArray[i].width = w / 6;
  imgArray[i].height = h / 7;
  imgArray[i].src = images[i];
  imgArray[i].stretch = "fill";
  wrap_layout.addChild(imgArray[i]);
  imgArray[i].on(gestures.GestureTypes.tap, function (args) {
    console.log("tap"+"|"+i);
  });

this my loop adding array of images to WrapLayout on nativescript is work well my problem is I'm trying to implement tap gesture for each image is work but doesn't specific index of Image any idea how solve it

作者: Elmissouri 的来源 发布者: 2017 年 12 月 27 日

回应 1


0

19 作者的声誉

决定
var onTap = function (args) {
console.log('tap');
 };
 images = raw_data.split("\n");
        for (i = 0; i < images.length; i++) {
          var m = re.exec(images[i]);
          idArray[i] = m[0];
          images[i] = images[i].replace(idArray[i], "");
          imgArray[i] = new imageModule.Image();
          imgArray[i].src = images[i];
          imgArray[i].stretch = "fill";
          stackArray[i] = new StackLayout();
          imgArray[i].id = "img";
          imgArray[i].width = sw;
          imgArray[i].height = sh;
          stackArray[i].id = "stack";
          stackArray[i].width = sw;
          stackArray[i].height = sh;
          stackArray[i].num = i;
          stackArray[i].addChild(imgArray[i]);
          wrap_layout.addChild(stackArray[i]);
          stackArray[i].on(buttonModule.Button.tapEvent, onTap, this);
        }

that's work for me

作者: Elmissouri 发布者: 2018 年 3 月 8 日
32x32