Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Eventlistener on dynamic view's not working

$
0
0

hi, in my project am using a dynamic view's am not able to add eventlistener to each view... i have a horizontal view and i want to add dynamic views[using array] to that vertical view.. am able to do that but when i want to add event listener to that dynamic view...when ever i click that view(am alerting some data)it is showing same values for all the views.

here is my code.

var mainview1=Ti.UI.createView({ left : '0%', top:'1%', height:'18%', layout:'horizontal', backgroundColor:'#BBB9B9', //top:10 });

for(var i=0;i<10;i++){
            var view[i]= Ti.UI.createView({
                Color:'gray',
                width:53,
                height:40,
                left:10,
                index:i
            });
                var l1 = Ti.UI.createLabel({
                    text:'label'+i,
                    font:{fontSize:13},
                    color:'#000',
                    width:'auto',
                    textAlign:'center',
                    height:'auto'
                    });
                    view[i].add(l1);
    //when i click the view's it should create annotation with the data getting from server but it is alerting only the last value////                          
                    view[i].addEventListener('click',function(e){
                        alert(view[i].index);       

                                var arr = [

                                  Ti.Map.createAnnotation({
                                      latitude:temp1[inc],
                                     longitude: temp2[inc],
                                         title: 'Itpl',
                                         animate: true,
                                     pincolor: Ti.Map.ANNOTATION_GREEN,
                                             image:'/img/imag.png'

                                        })
                                        ];
                                        mapview.annotations=arr;

                                    });

                                mainview1.add(view[i]);

                                }

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>