Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17480] Android: Android menuItem with actionView can't handle invalidateOptionsMenu()

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2014-11-25T18:58:36.000+0000
Affected Version/sRelease 3.3.0
Fix Version/sRelease 3.4.2, Release 3.5.0, Release 4.0.0
ComponentsAndroid
LabelsTCSupport, actionView, invalidateOptionsMenu(), menuItem, module_android, qe-manualtest, qe-testadded, regression
ReporterThomas Neerup
AssigneeGary Mathews
Created2014-06-19T10:55:09.000+0000
Updated2014-11-25T18:59:00.000+0000

Description

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

Attachments

FileDateSize
app.js2014-06-19T10:55:11.000+00001844

Comments

  1. Shuo Liang 2014-06-27

    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
  2. Thomas Neerup 2014-06-28

    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.
  3. Mauro Parra-Miranda 2014-08-10

    Thanks for your report. The Platform team will be setting the priority on this bug.
  4. jithinpv 2014-08-20

    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
  5. Aslan 2014-08-21

    Any chance to fix it? As this is regression it affects my existing application. Thanks.
  6. Gary Mathews 2014-09-30

    Master PR : https://github.com/appcelerator/titanium_mobile/pull/6048
  7. Thomas Neerup 2014-10-01

    Any chance this could become part of the 3.4.1 Release? this affects my existing application.
  8. Lokesh Choudhary 2014-10-03

    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
  9. Hieu Pham 2014-11-05

    3.4.X PR: https://github.com/appcelerator/titanium_mobile/pull/6316
  10. Lokesh Choudhary 2014-11-25

    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

JSON Source