GitHub Issue | n/a |
Type | Bug |
Priority | Medium |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2014-11-25T18:58:36.000+0000 |
Affected Version/s | Release 3.3.0 |
Fix Version/s | Release 3.4.2, Release 3.5.0, Release 4.0.0 |
Components | Android |
Labels | TCSupport, actionView, invalidateOptionsMenu(), menuItem, module_android, qe-manualtest, qe-testadded, regression |
Reporter | Thomas Neerup |
Assignee | Gary Mathews |
Created | 2014-06-19T10:55:09.000+0000 |
Updated | 2014-11-25T18:59:00.000+0000 |
Android menuItem with actionView can’t handle invalidateOptionsMenu() with Titanium SDK 3.3.0.GA.
TESTING ENVIRONMENT:
Mac OS X 10.9
Ti CLI 3.3.0
Titanium SDK: 3.3.0.RC, 3.3.0.GA and 3.2.3.GA
Android emulator and device 4.4.3
TEST CODE
var searchView = Ti.UI.Android.createSearchView();
var win = Ti.UI.createWindow({
backgroundColor : 'blue',
fullscreen : false,
activity : {
onCreateOptionsMenu : function(e) {
var menu = e.menu;
var menuItem = menu.add({
actionView : searchView,
icon : Ti.Android.R.drawable.ic_menu_search,
showAsAction : Ti.Android.SHOW_AS_ACTION_IF_ROOM | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
});
menuItem.addEventListener("click", function(e) {
Ti.API.info("I was clicked");
});
}
}
});
var data = [];
data[0] = Ti.UI.createTableViewRow({
hasChild : true,
title : 'Row 1'
});
data[1] = Ti.UI.createTableViewRow({
hasDetail : true,
title : 'Row 2'
});
data[2] = Ti.UI.createTableViewRow({
hasCheck : true,
title : 'Row 3'
});
data[3] = Ti.UI.createTableViewRow({
title : 'Row 4'
});
var tableview = Titanium.UI.createTableView({
data : data,
search : searchView,
searchAsChild : false
});
tableview.addEventListener('click', function(e) {
// event data
win.getActivity().invalidateOptionsMenu();
var index = e.index;
var section = e.section;
var row = e.row;
var rowdata = e.rowData;
Titanium.UI.createAlertDialog({
title : 'Table View',
message : 'row ' + row + ' index ' + index + ' section ' + section + ' row data ' + rowdata
}).show();
});
win.add(tableview);
win.open();
STEPS TO TEST
• Create a new project
• Update app.js file with sample code
• Run on android emulator/device
• Click the search button, see the searchView appear and works fine.
• Click a row, see the alert (win.getActivity().invalidateOptionsMenu(); i called)
• Click the search button again, now the searchView is not displayed
EXPECTED RESULT
It’s not working as expected in Ti SDK 3.3.0 but works fine in 3.2.3.GA
After the system calls onCreateOptionsMenu(), it retains an instance of the Menu you populate and will not call onCreateOptionsMenu() again unless the menu is invalidated for some reason. However, you should use onCreateOptionsMenu() only to create the initial menu state and not to make changes during the activity lifecycle. If you want to modify the options menu based on events that occur during the activity lifecycle, you can do so in the onPrepareOptionsMenu() method. This method passes you the Menu object as it currently exists so you can modify it, such as add, remove, or disable items. (Fragments also provide an onPrepareOptionsMenu() callback.) On Android 3.0 and higher, the options menu is considered to always be open when menu items are presented in the action bar. When an event occurs and you want to perform a menu update, you must call invalidateOptionsMenu() to request that the system call onPrepareOptionsMenu(). Ref: http://developer.android.com/guide/topics/ui/menus.html#ChangingTheMenu
I am aware of the onPrepareOptionsMenu callback. But consider the case of an application with 2 tabs. On both tabs there is a tableview and both tableviews have a searchview in the menus actionview. Now since the menu is attached to the tabcontroller Not the individual tabs, the menu needs to be rebuild when switching between the tabs. How can this be done? Just to be clear, this worked in 3.2.3, but not in 3.3.0.
Thanks for your report. The Platform team will be setting the priority on this bug.
Issue reproduces in Titanium SDK version 3.4.0 master, 3.3.0.GA Works fine in Titanium SDK version 3.2.3.GA Titanium Studio, build: 3.3.0.201407100905 Titanium Command-Line Interface CLI version 3.3.0, Android device : Motorola Moto G, Android version : 4.4.4
Any chance to fix it? As this is regression it affects my existing application. Thanks.
Master PR : https://github.com/appcelerator/titanium_mobile/pull/6048
Any chance this could become part of the 3.4.1 Release? this affects my existing application.
Verified the fix on latest 3.5.0 sdk & is fixed. Not closing as its not been backported to 3.4.1 sdk. Environment: Appc Studio : 3.4.0.201409261245 Ti SDK : 3.5.0.v20141002192515 Mac OSX : 10.9.4 Alloy : 1.5.1 CLI - 3.4.0 Code Processor: 1.1.1 Nexus 5 - Android 4.4.4
3.4.X PR: https://github.com/appcelerator/titanium_mobile/pull/6316
Verified the fix on latest master 3.6.0 sdk & is fixed. Closing Environment: Appc Studio : 3.4.1.201410281743 Ti SDK : 3.6.0.v20141125064916 CLI : 3.4.1 Alloy : 1.5.1 GA Code Processor : 1.1.1 MAC Yosemite : 10.10 Nexus 5 - Android 5.0