Can't open a new UI.window from a function?

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

I have a function which is supposed to display a new window, show information, and then call itself to show another window with the next piece of information. It works the first time, but when it calls itself the new window never shows up. Any help? Thanks!

function doTrial(my_info, i) {
    current_info = my_info[i];
 
    this.trialView = Ti.UI.createView({
        width:'100%',
        height:'auto',
    });
 
    this.trialWindow = Titanium.UI.createWindow({  
        title:'trial',
        backgroundColor:'#FFF',
        layout:'horizontal'
    });
 
    // Info label
    var lbStim1 = Titanium.UI.createLabel({
        color:'#000',
        text:current_info,
        font:{fontSize:30,fontFamily:'Helvetica Neue'},
        top:65,
        width:Ti.UI.SIZE,
        height:'auto',
        textAlign:'center'
    });
 
    // next button
    var btnNext = Ti.UI.createButton({
        title:'',
        width:80,
        height:80,
        right:0,
        top:125
    });
 
    // Call self to display next piece of info
    btnNext.addEventListener('click', function(e) {
        doTrial(my_info, i+1);
    });
 
    this.trialView.add(lbStim1);
    this.trialView.add(btnNext);
    trialWindow.add(trialView);
}

— asked 10 months ago by Jordan U
0 Comments

3 Answers

Accepted Answer

I think a better way to do this is to just change the value of lbStim1 on click of next button.If every time you will create a new window by using a recursive function, the performance of the application may become poor and window may take some time to open.

you need to provide a working example of code to get some help here... what function calls this function? what is "this"? where is trailWindow defined? is this.trialWindow the same as trialWindow?

You never open this.trialWindow nor you use it within the function. In your case you dont need multiple Windows. You could reuse the same window and the controls also.

Therefore the Basic idea would be Exchange the data but Not creating the UI over and over again.

Your Answer

Think you can help? Login to answer this question!