Finding the index of the scrollview

You must Login before you can answer or comment on any questions.

Hi, I have created a scrollview inside a view.

Window > View > Scrollview

Scrollviews are again views

I am trying to alert the index of the current selected scroll view and I am not able to get it.

var data = [];
//
for (var i=1;i<4;i++){
    var row = Titanium.UI.createView();
    row.backgroundImage = "images/img"+i+".png";
    row.addEventListener('singletap', function(e)
    {
        showAlert(e);
    });
 
    data.push(row);
}
 
function showAlert(e){
    var alertDialog = Titanium.UI.createAlertDialog({
        title: 'Hello',
        message: 'You got mail : ' +e.source.index,
        buttonNames: ['OK','Doh!']
    });
    alertDialog.show();
}
I have tried e.source and it alerts [object] TiUiView

How to find out which View is selected???

Thanks fo rany help

2 Answers

Accepted Answer

Hi, You could try explicity adding an 'index' property, which should work.

eg:

var data = [];
//
// note the change of the i value starting from zero.
for (var i=0;i<3;i++){
    var row = Titanium.UI.createView();
    row.backgroundImage = "images/img"+(i+1)+".png";
    // explicitly set a property called 'index' (you could use any name)
    row.index = i;
    row.foo = 'bar'+i;
    row.addEventListener('singletap', function(e)
    {
        showAlert(e);
    });
 
    data.push(row);
 
 
}
 
function showAlert(e){
    var alertDialog = Titanium.UI.createAlertDialog({
        title: 'Hello',
        message: 'You got mail : ' +e.source.index+ ' foo='+e.source.foo,
        buttonNames: ['OK','Doh!']
    });
    alertDialog.show();
}

Thanks, I will try this later today and update on how it goes.

Regards

Your Answer

Think you can help? Login to answer this question!