Tag Archives: actionbar

Android menu item set onClick method from xml

There is a simple and easy way to set the callback method for a view from the xml describing the view.

We simply need to add to our view:

android:onClick="doTheClick"

And then in the code implement the “doTheClick” method.

public void doTheClick(View v) {    	
		//do smth here
	}

To do this for a menuItem you just need to change the “doTheClick” so it accepts MenuItem argument.

public void doTheClick(MenuItem mi) {    	
		//do smth here
	}