android - Fragment must be attached to a SherlockFragmentActivity -
ok have slight problem in code.
public class menufragment extends sherlocklistfragment {
is extending sherlock jar should allow me use action bar within fragment when run code getting
caused by: java.lang.illegalstateexception: menufragment must attached sherlockfragmentactivity.
so changed extends
public class mainactivity extends actionbaractivity {
to
public class mainactivity extends sherlockfragmentactivity{
which runs code action bar no longer visible
my fragment class,
public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { sethasoptionsmenu(true); return view; } @override public void oncreateoptionsmenu(menu menu, menuinflater inflater) { super.oncreateoptionsmenu(menu, inflater); inflater.inflate(r.menu.menu_main, menu); } @override public boolean onoptionsitemselected(com.actionbarsherlock.view.menuitem item){ switch (item.getitemid()) { case r.id.shuffle: return true; case r.id.quit: return true; default: return false; } }
which importing
import com.actionbarsherlock.app.sherlocklistfragment; import com.actionbarsherlock.view.menu; import com.actionbarsherlock.view.menuinflater;
main
public class mainactivity extends actionbaractivity { songadapter adapter; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } }
hmmm instead of
mainactivity extends actionbaractivity
just use
mainactivity extends sherlockfragmentactivity { //you code fragment goes here }
whatever use fragment ned use sherlockfragment, in case of activity have sherlockactivity in here. else not match.
follow below link understand how go sherlock library: https://guides.codepath.com/android/actionbar-tabs-with-fragments
let me know if helps.
Comments
Post a Comment