Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


why menuitemcompat getactionprovider returns null using -'java,android'


why menuitemcompat getactionprovider returns null  using -'java,android'

I tried to use android.support.v7.widget.ShareActionProvider on actionbar in my app. So I followed the example from android document but got some issues.
Here's my menu xml:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res-auto" >

    <item
        android:id="@+id/action_share"
        android:orderInCategory="100"
        android:icon="@drawable/ic_action_share"
        android:title="@string/action_share"
        myapp:showAsAction="ifRoom"
        myapp:actionProviderClass="android.support.v7.widget.ShareActionProvider" />

</menu>


here's my code to create the share action button:

@Override
public void onCreateOptionsMenu (Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.share, menu);
    MenuItem shareItem = menu.findItem(R.id.action_share);
    ShareActionProvider mShareActionProvider = (ShareActionProvider)MenuItemCompat.getActionProvider(shareItem);
    mShareActionProvider.setShareIntent(getDefaultIntent());
    super.onCreateOptionsMenu(menu, inflater);
}


My question is:


MenuItemCompat.getActionProvider(shareItem) always returns null for me, why's that?
When I comment those lines, the share button appears on the bar but does nothing while clicking, how to fix it(if question 1 can't be solved)?


btw, I checked codes of MenuItemCompat.getActionProvider, it looks like this method will check if the menu item implements SupportMenuItem interface and returns fail if it isn't. How could I deal with it?
    

asked Sep 7, 2015 by rajesh
0 votes
13 views



Related Hot Questions



Government Jobs Opening


...