java - Android: getMenuInflater().inflate throws android.widget.ShareActionProvider cannot be cast to android.support.v4.view.ActionProvider -


i'm developing android app , having trouble implementing share button on template "master / detail flow"

when create menu on itemdetailactivity extends appcompatactivity (however, i've tried extending actionbaractivity) following error java.lang.classcastexception: android.widget.shareactionprovider cannot cast android.support.v4.view.actionprovider in line:

getmenuinflater().inflate(r.menu.menu_ficha, menu);

here code: java

public class itemdetailactivity extends appcompatactivity {  shareactionprovider mshareactionprovider;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_item_detail);      // show button in action bar.     getsupportactionbar().setdisplayhomeasupenabled(true);       if (savedinstancestate == null) {         // create detail fragment , add activity         // using fragment transaction.         bundle arguments = new bundle();         arguments.putstringarray(itemdetailfragment.arg_item_id,                       getintent().getstringarrayextra(itemdetailfragment.arg_item_id));         itemdetailfragment fragment = new itemdetailfragment();         fragment.setarguments(arguments);         getsupportfragmentmanager().begintransaction()                 .add(r.id.item_detail_container, fragment)                 .commit();     } }  @override public boolean onoptionsitemselected(menuitem item) {     int id = item.getitemid();     if (id == android.r.id.home) {          navutils.navigateupto(this, new intent(this, itemlistactivity.class));         return true;     }      return super.onoptionsitemselected(item); }  @override public boolean oncreateoptionsmenu(menu menu) {     getmenuinflater().inflate(r.menu.menu_ficha, menu);     // access share item defined in menu xml     menuitem shareitem = menu.finditem(r.id.menu_item_share);      // access object responsible     // putting sharing submenu      mshareactionprovider = (shareactionprovider)     menuitemcompat.getactionprovider(shareitem);     // create intent share content     setshareintent();      return true; };  private void setshareintent() {      if (mshareactionprovider != null) {          // create intent contents of textview         intent shareintent = new intent(intent.action_send);         shareintent.settype("text/plain");         shareintent.putextra(intent.extra_subject, "testing oceanbook");         shareintent.putextra(intent.extra_text, itemdetailfragment.data[1]);          // make sure provider knows         // should work intent         mshareactionprovider.setshareintent(shareintent);     } } } 

and xml of menu:

<menu xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android" xmlns:oceanbook="http://schemas.android.com/apk/res-auto"> <item     android:id="@+id/menu_item_share"     android:title="compartir"     oceanbook:showasaction="ifroom"     oceanbook:actionproviderclass="android.widget.shareactionprovider" /> </menu> 

just in case important, xml of activity:

<framelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/item_detail_container" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".itemdetailactivity" tools:ignore="mergerootframe" /> 

could me please?

replace:

oceanbook:actionproviderclass="android.widget.shareactionprovider" 

with:

oceanbook:actionproviderclass="android.support.v7.widget.shareactionprovider" 

if using appcompat-v7 action bar backport, have use shareactionprovider appcompat-v7 action bar backport. since inheriting appcompatactivity, using backport.


Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -