Search code examples
androidandroid-menuandroid-sharing

Unable to click on Share button


I am trying but unable to click the share button while the up button works fine.

I have the following code in a class that extends AppCompatActivity :

@Override
public boolean onCreateOptionsMenu( Menu menu ) {

    MenuInflater inflater = getMenuInflater();

    inflater.inflate( R.menu.log_display, menu );

    return super.onCreateOptionsMenu( menu );
    }

and

@Override
public boolean onOptionsItemSelected( MenuItem item ) {
    Logger.debug( item.getItemId()+" ==========" );
    switch ( item.getItemId() ) {

        case android.R.id.home:

            super.onBackPressed();

            break;

        case R.id.menu_item_share:
            Logger.debug( "MENU SHARE ITEM" );

            break;

        default:
            Logger.debug( "Default in menu" );
    }
}

I tried the onClickListener method from the onCreateOptionsMenu but that did not work as well. Any ideas ?

EDIT : Xml file

  <?xml version="1.0" encoding="utf-8"?>
  <menu xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto">
  <item
    android:id="@+id/menu_item_share"
    android:title="@string/log_share"
    app:showAsAction="always"
    app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
    app:popupTheme="@style/Theme.AppCompat.Light.DarkActionBar" />
    </menu>

Solution

  • The offending line was in the menu xml file :

        app:actionProviderClass="android.support.v7.widget.ShareActionProvider"
    

    Thanks for the help @Darshan Kachhadiya