android - Trouble returning a subclass of fragment as a fragment -
i have class named singlefragmentactivity want class workoutactivity extend. when override abstract method createfragment code in method, error, , when run code, ---
error:(12, 8) error: workoutactivity not abstract , not override abstract method createfragment() in singlefragmentactivity error:(16, 24) error: createfragment() in workoutactivity cannot override createfragment() in singlefragmentactivity return type android.app.fragment not compatible android.support.v4.app.fragment error:(15, 5) error: method not override or implement method supertype error:(20, 43) error: incompatible types: workoutfragment cannot converted fragment
i believe code correct, extend class , override method in same way in several other places in app. here code involved functions.
public class workoutfragment extends fragment { public static final string extra_alreadycreated_id = "alreadycreated"; private exadapter adapter; private listview listview; private arraylist<set> sets; private workout w; public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); uuid workoutid = (uuid) getarguments().getserializable(extra_alreadycreated_id); w = workoutmaster.get(getactivity()).getworkout(workoutid); } public view oncreateview(layoutinflater inflater, viewgroup parent,bundle savedinstancestate) { view v = inflater.inflate(r.layout.fragment_workout, parent, false); return v; } public static workoutfragment newinstance(uuid workoutid) { bundle args = new bundle(); args.putserializable(extra_alreadycreated_id, workoutid); workoutfragment fragment = new workoutfragment(); fragment.setarguments(args); return fragment; } } public class workoutactivity extends singlefragmentactivity { @override protected fragment createfragment() { uuid createdworkoutid = (uuid) getintent().getserializableextra(workoutfragment.extra_alreadycreated_id); return workoutfragment.newinstance(createdworkoutid); } } public abstract class singlefragmentactivity extends fragmentactivity { protected abstract fragment createfragment(); protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_fragment); fragmentmanager fm = getsupportfragmentmanager(); //calling support part make compatible honeycomb devices... //otherwise, call getfragmentmanager fragment fragment = fm.findfragmentbyid(r.id.fragmentcontainer); if(fragment == null) { fragment = createfragment(); fm.begintransaction().add(r.id.fragmentcontainer, fragment).commit(); } } }
i've excluded imports, exist in project. before run project, error occurs @ return statement of createfragment() in workoutactivity. appreciate help.
Comments
Post a Comment