Search code examples
javascriptandroidtitaniumtitanium-mobile

Titanium window + remove method


I have a defined a window like this.

var fenetreBase = Titanium.UI.createWindow({...});

this window can display 3 views which I'm adding like so

fenetreBase.add(vueimage.vue);
fenetreBase.add(vuegraphe.vue);

etc.

Currently, when I want to change the displayed view, I'm forced to remove all (even those who are not add).

fenetreBase.remove(vuegraphe.vue);
fenetreBase.remove(vueimage.vue);

Is there a simple way to do something like the example below?

 fenetreBase.remove(this.view); // which would be very cool.

Solution

  • You could keep a hold of the current view and then have a function that handles the add/remove actions.

    var currentView = null;
    
    function replaceView(view) {
        if(currentView) {
           window.remove(currentView);
           currentView = null;
        }
    
        currentView = view;
        window.add(currentView)
    }
    

    Then when you find out which view to show you just call the function.

    replaceView( viewToShow );