我如何得到leftButton或rightButton是否在createAnnotation中单击?

时间:2012-03-03 11:42:38

标签: titanium titanium-mobile titanium-modules

我创建了一个Map视图基础应用程序。我想要做。当我点击rightButton时,显示它的地址。 但是,我是如何观察按钮是否点击?

正常按钮我

button.addEventListener('click',function(){
<do something>
});

但是,在mapView中,我该怎么做?

2 个答案:

答案 0 :(得分:1)

我假设你想把按钮放在注释上。

创建注释的参数: -

var annotationParams = 
{
latitude:33.74511,
longitude:-84.38993,
title:"Example",
subtitle:'Atlanta Braves Stadium foo',
pincolor: isAndroid ? "orange" : Titanium.Map.ANNOTATION_RED,
animate:true,
myid:1,
leftButton:currentWindow.photo, // for image
rightButton: Titanium.UI.iPhone.SystemButton.DISCLOSURE
};

var mapAnnotation = Titanium.Map.createAnnotation(annotationParams);

var mapview  = Titanium.Map.createView
({
    mapType: Titanium.Map.STANDARD_TYPE,
    region:{latitude:33.74511, longitude:-84.38993, latitudeDelta:0.5, longitudeDelta:0.5},
    animate:true,
    regionFit:true,
    userLocation:true,
    annotations:[mapAnnotation],
    top:'0dp',
    height:'450dp'
});     
currentWindow.add(mapview);

现在处理点击地图视图,如: -

// map view click event listener
mapview.addEventListener('click',function(evt)
{
   if (evt.clicksource == 'rightButton')
   {
    //getDetails();
    createActionSheet();        
   }
   else if(evt.clicksource == 'leftButton')
   {
      // do some thing
   }
 } 

答案 1 :(得分:1)

我想 这对你很有用,

mapview.addEventListener('click', function(evt) {

    Ti.API.info("Annotation " + evt.title + " clicked, id: " + evt.annotation.myid);

    // Check for all of the possible names that clicksouce
    // can report for the left button/view.
    if (evt.clicksource == 'leftButton' || evt.clicksource == 'leftPane' ||
        evt.clicksource == 'leftView') {
        Ti.API.info("Annotation " + evt.title + ", left button clicked.");
    }
});