Having trouble creating a toolbar - what am I doing wrong?
Hi folks,
I replaced app.js with the following code, mostly taken from the KitchenSink:
var topWin = Titanium.UI.createWindow();
var b1 = Titanium.UI.createButton({
title:'One Button - Left',
width:200,
height:40,
top:10
});
b1.addEventListener('click', function()
{
var b = Titanium.UI.createButton({
title:'Button',
// style:Titanium.UI.iPhone.SystemButtonStyle.BORDERED,
enabled:false
});
b.enabled = false;
topWin.setToolbar([b]);
});
topWin.add(b1);
topWin.open();
Unfortunately on Android it just crashes on startup, and on the iPhone when I click on the button, nothing happens. Any ideas what I'm doing wrong?
2 Answers
-
I think you should not add comment (//) in your createButton
And you should createToolbar instead of setToolbar (since it does not exist)
so your code should be more like :
var topWin = Titanium.UI.createWindow(); var b1 = Titanium.UI.createButton({ title:'One Button - Left', width:200, height:40, top:10 }); b1.addEventListener('click', function() { var b = Titanium.UI.createButton({ title:'Button' }); var tb = Titanium.UI.createToolbar([b]); topWin.add(tb) }); topWin.add(b1); topWin.open();
-
Thanks for the reply!
I'm afraid that's not true about setToolbar - setToolbar() is used in a number of parts of KitchenSink, and it seems it can be used interchangeably with window.toolbar = […].
Looking into the differences between the KitchenSink demo and my own code, the only difference I could find is that I wasn't using a tabbed window. Digging around, I found this in the docs: "this is only valid when the window is a child of a tab.". So it looks like the solution here is to use createToolbar() if the window is not part of a tab. Since the toolbar only works on the iPhone anyway, perhaps I'll look into a cross-platform solution instead.