Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

2 buttons with 2 different views - display error when navigating back

I've managed to get two buttons to open up two different views using the code below. However, when I navigate back to the first/main page (using the back button in the top left hand corner) only one of the buttons appears. The button that appears is always the one I clicked. For example, if I click button one, it opens up a new window, but when I navigate back to the main page only button one is displayed (and button two is displayed when I navigate back if I clicked button two). How do I reset the original button view on the main page? Or remove a listener? Or do I have to do something else entirely? Any help appreciated. Thanks. John

var win = Titanium.UI.currentWindow;

var bb2 = Titanium.UI.createButtonBar({
    labels:['One', 'Two'],
    backgroundColor:'maroon'
});
var flexSpace = Titanium.UI.createButton({
    systemButton:Titanium.UI.iPhone.SystemButton.FLEXIBLE_SPACE
});

win.setToolbar([flexSpace,bb2,flexSpace]);

bb2.addEventListener('click', function(e)
{
if (e.index == 0)
{
    bb2.labels = ['One'];
    win = Titanium.UI.createWindow({
    url:'../examples/arthur1.js',
    title:'View 1',
    backgroundColor:'#fff',
    barColor:'#111'     
});
}
if (e.index == 1)

{
    bb2.labels = ['Two'];
    win = Titanium.UI.createWindow({
    url:'../examples/arthur2.js',
    title:'View 2',
    backgroundColor:'#fff',
    barColor:'#111'         
});
}


Titanium.UI.currentTab.open(win,{animated:true});
});
— asked September 20th 2010 by John Howell
  • buttonbar
  • display
  • navigtion
  • reset
0 Comments

1 Answer

  • Accepted Answer

    Then leave the tittle dont change it. i mean in
    1st method :

    bb2.addEventListener('click', function(e){
    if (e.index == 0)
    {
    //bb2.labels = ['One'];
    your code
    }

    if (e.index == 1)
    {
    bb2.labels = ['Two'];
    your code
    }

    2nd method :

    you have to add some code for back button i.e.,

    backbutton.addEventListener('click', function()
    {
    bb2.labels = ['One', 'Two'];
    }

    for this you need to create one more back button which should be implemented by you

    — answered September 20th 2010 by Varun Atluri
    permalink
    1 Comment
    • Thank you once again Varun. I removed the "bb2.labels" text in both cases and it works just as I wanted it to (I wasn't sure how to implement the second method). Cheers. John

      — commented September 20th 2010 by John Howell
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.