I have added a share button on action item, I am trying to handle click event on the action button (button in action bar). I tried with the below code but I know I have to add clicklistener for this. Below is my activity code :
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu items for use in the action bar
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.activity_main, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.d("", "Inside the menu selected");
System.out.println("Inside the menu selected");
// Handle presses on the action bar items
switch (item.getItemId()) {
case R.id.action_share:
shareImage();
return true;
default:
return super.onOptionsItemSelected(item);
}
}
This is code for my menu layout :
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/menu_settings"
android:orderInCategory="100"
android:showAsAction="never"
android:title="@string/menu_settings"/>
<item android:id="@+id/action_share"
android:icon="@drawable/share2"
android:title="search"
android:showAsAction="always" />
</menu>
I also tried to refer : onOptionsItemSelected() not called when clicking on menu item which has an actionLayout set on it
But I am not getting what is itemchooser in the answer.
Please help me on this.
Thanks, Aman