Closed GiuseppeIuculano closed 12 years ago
It should be
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// TODO Auto-generated method stub
getSupportMenuInflater().inflate(R.menu.menuhome, menu);
MenuItem menuItem = menu.findItem(R.id.menu_share);
ShareActionProvider mShareActionProvider = (ShareActionProvider) menuItem.getActionProvider(); //line 387
Intent shareIntent = new Intent(Intent.ACTION_SEND);
shareIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
shareIntent.setType("text/plain");
shareIntent.putExtra(Intent.EXTRA_TEXT, getString(R.string.sharesubject));
shareIntent.putExtra(Intent.EXTRA_SUBJECT,getString(R.string.sharetext));
mShareActionProvider.setShareIntent(shareIntent);
}
your menu file didn't have title and icon too.
The key part to take away is that you need to inflate the menu before calling findItem
. You don't need an icon but a title is required if the item were to be pushed into the overflow menu.
I'm trying to use ShareActionProvider with actionbarsherlock, but i got:
The relevant code on onCreateOptionsMenu(Menu menu) is this:
and the menuhome.xml has this: