Hi, I have an Android app which has a custom tabbar implemented. When launching it in emulator, switching tabs works fine. There are no errormessages in the log. However, after installing it on my device, switching tabs makes the app crash.
Does anyone have had a similar error or has any ideas where it could come from?
1 Answer
So here is the Code that creates the tabbar. my windowobject is a module that implements the singleton-pattern to make it availible in the global scope without using ti.app
I inserted a few alerts to "log" on my device (since the application works fine in the debugger). When switching tabs, I can see that the gradient switches and the app crashes when trying to add the new view. So I thought I could see the alerts until win1.add(activeTab.view); But Somehow, I don't get any alerts at all
Here is my code
var win = require('win') function tabBar(settings, win1) { var win1 = win.getWindow(); var tabs = new Object(); var activeTab = null; function resetActiveTab() { if (activeTab != null) { activeTab.setBackgroundGradient({ colors : ['transparent', 'transparent'] }); win1.remove(activeTab.view); } } function setActiveTab(tab) { //remove previous active Tab alert('reset active tab') resetActiveTab(win1) tab.setBackgroundGradient({ type : 'linear', colors : ['#00b7f0', '#1c61bc'], startPoint : { x : 0, y : 0 }, endPoint : { x : 2, y : 50 }, backFillStart : false }); activeTab = tab; //set view of tab on the window alert('set active tab') win1.add(activeTab.view); } function addClickEventListener(tabItem) { tabItem.addEventListener('click', function(e) { alert('click') var item = e.source; //assert that the event doesnt get fired by the label if (item.text != null) { item = item.parent; } if (item != activeTab) { setActiveTab(item); } }); }; // Create the container for the tab items var tabBar = Ti.UI.createView({ height : settings.height, top : 0, width : '100%', backgroundGradient : { type : 'linear', colors : ['#000001', '#666666'], startPoint : { x : 0, y : 0 }, endPoint : { x : 2, y : 50 }, backFillStart : false }, }); //calculate width of each item var width = 100 / settings.items.length; for (var i = 0; i < settings.items.length; i++) { // Go through each item and create an imageView //calculate distance to left var left = width * i tabs[i] = Titanium.UI.createView({ width : width + '%', height : settings.height, left : left + '%' }); tabs[i].view = settings.items[i].view; tabs[i].view.top = settings.height; var tmpLabel = Ti.UI.createLabel({ text : settings.items[i].title, color : 'white', visible : true, textAlign : Ti.UI.TEXT_ALIGNMENT_CENTER }) tabs[i].add(tmpLabel); addClickEventListener(tabs[i]); // Add to the container window tabBar.add(tabs[i]); } setActiveTab(tabs[0]); return tabBar; } module.exports = tabBar
Your Answer
Think you can help? Login to answer this question!