Here is the runtime exception
java.lang.ClassCastException: android.support.v7.widget.ShareActionProvider cannot be cast to android.view.View
I have tried many different ways of doing this but I know it has to do with the ShareActionProvider I can add links to sites where there are several ways of doing this but it is not working here is the entire code
And by "this" I mean instantiating the ShareActionProvider
Please to not set this as duplicate it is not I have looked on SO and none of them have helped ... Sod to say
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
// TODO: Implement this method
MenuInflater inflator = getMenuInflater();
inflator.inflate(R.menu.sidebar_menu, menu);
SubMenu subMenu = menu.addSubMenu("Themes");
subMenu.add(0 , blue , 0 , "Blue");
subMenu.add(0, pink , 1, "Pink");
items = subMenu.getItem().getItemId();
// tool bar menu
MenuItem mi = menu.findItem(R.id.searchable);
mi.setIcon(android.R.drawable.ic_search_category_default);
SearchView searchView = (SearchView)MenuItemCompat.getActionView(mi);
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
sap = (ShareActionProvider) MenuItemCompat.getActionProvider(menu.findItem(R.id.share));
Intent intentShare = new Intent(Intent.ACTION_SEND);
intentShare.setType("text/plain");
intentShare.putExtra(Intent.EXTRA_SUBJECT ,"Subject here");
intentShare.putExtra(Intent.EXTRA_TEXT , "Here is the share content body");
startActivity(Intent.createChooser(intentShare,"Share via"));
sap.setShareIntent(intentShare);
MenuItemCompat.OnActionExpandListener el = new MenuItemCompat.OnActionExpandListener(){
@Override
public boolean onMenuItemActionCollapse(MenuItem item) {
// Do something when action item collapses
return true; // Return true to collapse action view
}
@Override
public boolean onMenuItemActionExpand(MenuItem item) {
// Do something when expanded
return true; // Return true to expand action view
}};
MenuItem actionMenuItem = menu.findItem(R.id.searchable);
// Assign the listener to that action item
MenuItemCompat.setOnActionExpandListener(actionMenuItem,el);
return super.onCreateOptionsMenu(menu);
}
Can anyone help please ! I think I have been clear enough with this issue I am having if needed I can post up the menu.XML file along with appmanifest.XML along with the other XML files which I see no reason to put up ... Thank you
Here is the menu.xml as requested
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/searchable"
android:title="@string/tbmenuitem_search"
myapp:showAsAction="ifRoom|collapseActionView"
myapp:actionViewClass="android.support.v7.widget.SearchView"
/>
<item
android:id="@+id/share"
android:showAsAction="ifRoom"
android:title="@string/sharetitle"
myapp:actionViewClass="android.support.v7.widget.ShareActionProvider"
/>
<item
android:id="@+id/playlist"
android:title="Play lists"
/>
<item
android:id="@+id/muteoption"
android:title="Mute"
/>
<item
android:id="@+id/unmuteoption"
android:title="UnMute"
/>
<item
android:id="@+id/sharewidget"
android:title="Share"
/>
[Edited] my XML file actionViewClass should have been actionViewProvider hence the run time error .