Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-12398] Android: TabGroup activity should work like Window activity

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionCannot Reproduce
Resolution Date2018-12-12T15:34:48.000+0000
Affected Version/sRelease 3.0.2, Release 3.1.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterArthur Evans
AssigneeUnknown
Created2013-01-23T20:09:06.000+0000
Updated2018-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.

Comments

  1. jithinpv 2013-03-15

    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
  2. Yordan Banev 2018-10-05

    I can't reproduce the issue with 7.0.0.GA.
  3. Samir Mohammed 2018-12-12

    Closing ticket. Unable to reproduce using SDK version 8.0.0.v20181212023313

JSON Source