[TIMOB-11340] Android: Can't add menu items to ActionBar-style tab group
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2012-10-15T21:39:30.000+0000 |
Affected Version/s | Release 3.0.0 |
Fix Version/s | Release 3.0.0, Release 3.1.0, 2012 Sprint 21 API, 2012 Sprint 21 |
Components | Android |
Labels | api, tabgroup |
Reporter | Arthur Evans |
Assignee | Josh Roesslein |
Created | 2012-10-10T01:19:01.000+0000 |
Updated | 2012-12-04T00:28:00.000+0000 |
Description
In 3.0, we have support for ActionBar-based tabs and menu items.
However, to add a menu item to the action bar, we need to access the current activity. Attempting to access the window activity for the tab window doesn't work in 3.0, though it works in 2.X. Currently attempting to set the optionsmenu on the window activity in a tab group crashes for *both* 2.X and 4.X devices on 3.0.
Using Ti.Android.currentActivity fails in the same way.
I think there are two issues here:
* We don't seem to expose the activity associated with the tab group in any fashion I can see.
* We have a regression that is causing the following code to throw an exception in 3.0.
//
// create base UI tab and root window
//
var tg = Ti.UI.createTabGroup();
var win1 = Titanium.UI.createWindow({
title : 'Tab 1',
backgroundColor : '#fff',
layout : 'vertical'
});
var label1 = Titanium.UI.createLabel({
color : '#999',
text : 'I am Window 1',
font : {
fontSize : 20,
fontFamily : 'Helvetica Neue'
},
textAlign : 'center',
width : 'auto'
});
var tf = Titanium.UI.createTextField({
hintText : 'Hello',
width : 300,
color : 'white',
backgroundColor: '#333',
});
win1.add(label1);
win1.add(tf);
if (Ti.Platform.name === 'android') {
win1.addEventListener('open', function(e) {
Ti.API.info("win1.activity is: " + win1.activity);
Ti.API.info("Ti.Android.currentActivity is: " + Ti.Android.currentActivity);
win1.activity.onCreateOptionsMenu = function(e) {
var menu = e.menu;
var menuItem = menu.add({
title : "Item 1",
showAsAction : Ti.Android.SHOW_AS_ACTION_WITH_TEXT
});
menuItem.icon = "KS_nav_ui.png";
menuItem.addEventListener("click", function(e) {
Ti.API.info("I was clicked");
});
};
});
}
var tab1 = Ti.UI.createTab({
title : 'Quarks',
window : win1
});
tg.addTab(tab1);
var win2 = Titanium.UI.createWindow({
title : 'Tab 2',
backgroundColor : '#f33',
});
var tab2 = Ti.UI.createTab({
title : 'Snoodles',
window : win2
});
tg.addTab(tab2);
tg.open();
Tested with SDK 3.0.0.v20121009034227.
Nexus 7
Galaxy S 2 (2.3.6).
Error message is:
E/TiExceptionHandler( 9242): (main) [170,233] ----- Titanium Javascript Runtime Error -----
E/TiExceptionHandler( 9242): (main) [0,233] - In ti:/window.js:313,34
E/TiExceptionHandler( 9242): (main) [0,233] - Message: Uncaught TypeError: Cannot call method 'extend' of undefined
E/TiExceptionHandler( 9242): (main) [0,233] - Source: this.window._internalActivity.extend(this.cachedActivityProxy);
Created [PR #3191 | https://github.com/appcelerator/titanium_mobile/pull/3191] to resolve the crash seen with this test case. Run the test case and verify there is no crash and you can see the menu item.
master PR: https://github.com/appcelerator/titanium_mobile/pull/3191
Created [PR #3231](https://github.com/appcelerator/titanium_mobile/pull/3231) to back port fix into 3.0 release.
3.0.X PR: https://github.com/appcelerator/titanium_mobile/pull/3231
Tested with 3.0.0.v201211300200208 on Galaxy S3 4.0.4