Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5997] Android activity.onCreateOptionsMenu itemMenu does not support addEventListener

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionInvalid
Resolution Date2018-11-03T21:11:08.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsandroid, menuItem
ReporterLorenzo Piccinini
AssigneeShak Hossain
Created2018-10-30T00:18:12.000+0000
Updated2019-01-08T12:05:22.000+0000

Description

		
		var activity = win.getActivity();
		// Re-create Menu
		if(activity){
			activity.onCreateOptionsMenu = function(e){
		    		var item, menu;
		            menu = e.menu;
		            menu.clear();
			    var menuItem = menu.add({
			      visible: true,
			      title: 'title1',
			      showAsAction : Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
			    });
			    var menuItem2 = menu.add({
			      title : "title2",
			      visible: true,
			      showAsAction : Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
			    });  
			    menuItem.addEventListener('click', function(e){
			    		console.log("aaaaa");
			    });
			    activity.invalidateOptionsMenu();
			};
		}
	
{noformat} [ERROR] : TiExceptionHandler: (main) [158,158] menuItem.addEventListener('click', function(e){ [ERROR] : TiExceptionHandler: ^ [ERROR] : TiExceptionHandler: TypeError: menuItem.addEventListener is not a function [ERROR] : TiExceptionHandler: at Activity.activity.onCreateOptionsMenu (eval at Module._compile (/app.js:728:13), :404:14) [ERROR] : V8Exception: Exception occurred at undefined:404: Uncaught TypeError: menuItem.addEventListener is not a function {noformat}

Comments

  1. Lorenzo Piccinini 2018-11-02

    You can close this ticket, it's not a bug, I solve it, mixed problems in my code.
  2. Andrea Vitale 2019-01-08

    @Lorenzo can you please give a description about your code? I too cannot call _addEventListener_ on MenuItems. How did you solve it?

JSON Source