[TIMOB-12398] Android: TabGroup activity should work like Window activity
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Closed |
Resolution | Cannot Reproduce |
Resolution Date | 2018-12-12T15:34:48.000+0000 |
Affected Version/s | Release 3.0.2, Release 3.1.0 |
Fix Version/s | n/a |
Components | Android |
Labels | n/a |
Reporter | Arthur Evans |
Assignee | Unknown |
Created | 2013-01-23T20:09:06.000+0000 |
Updated | 2018-12-12T15:34:53.000+0000 |
Description
With Windows, it's possible to create menus before opening the window, by assigning Window.activity.onCreateOptionsMenu.
var win = Ti.UI.createWindow({
fullscreen: true
});
var activity = win.activity;
activity.onCreateOptionsMenu = function(e){
var menu = e.menu;
var menuItem = menu.add({ title: "Item 1" });
menuItem.icon = "item1.png";
menuItem.addEventListener("click", function(e) {
Ti.API.debug("I was clicked");
});
};
win.open();
For a TabGroup, although TabGroup.activity is now exposed, you cannot assign an onCreateOptionsMenu function until after the TabGroup is opened. The following code demonstrates the issue:
var tabGroup = Titanium.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff'
});
var tab1 = Titanium.UI.createTab({
icon : 'KS_nav_views.png',
title : 'Tab 1',
window : win1
});
var addMenu = function() {
tabGroup.activity.onCreateOptionsMenu = function(e) {
var menu = e.menu;
var menuItem = menu.add({
title : "Item 1"
});
menuItem.icon = "item1.png";
menuItem.addEventListener("click", function(e) {
Ti.API.debug("I was clicked");
});
};
}
addMenu(); // To work around issue, comment out this line and
// uncomment the addEventListener call below.
/*
tabGroup.addEventListener("open", function() {
addMenu();
tabGroup.activity.invalidateOptionsMenu();
});
*/
tabGroup.addTab(tab1);
tabGroup.open();
As written, it doesn't add a menu item. If you comment out the standalone addMenu call and uncomment the addEventListener call, the menu item is added as expected.
Expected Results:
Menu item is added as on a Window, without needing to add an open event listener or call invalidateOptionsMenu.
Issue reproduces with Titanium Studio, build: 3.0.1.201212181159 Titanium SDK version: 3.1.0 (03/11/13 15:43 0c88429) Titanium SDK version: 3.0.2 (02/07/13 16:46 a4def81) Device: Samsung galaxy s duos Android version: 4.0.4 jithinpv
I can't reproduce the issue with 7.0.0.GA.
Closing ticket. Unable to reproduce using SDK version
8.0.0.v20181212023313