android - Starting a Fragment without UI -


i have code in activity

@override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);      setcontentview(r.layout.activity_main);     fragment workerfragment = new xmlworker();     android.app.fragmentmanager fm= getfragmentmanager();     fragmenttransaction fragtrans = fm.begintransaction();     fragtrans.add(workerfragment, "work");     fragtrans.commit();   } 

the fragments name xmlworker. doesnot have ui , use parse xmls.

on line of code

 fragtrans.add(workerfragment, "work"); 

i error

the method add(fragment, string) in type fragmenttransaction not applicable arguments (fragment, string).

why? doing wrong?

edit: because using

import android.support.v4.app.fragment; import android.support.v4.app.fragmentactivity; import android.support.v4.app.fragmentmanager; 

??

the method add(fragment, string) in type fragmenttransaction not applicable arguments (fragment, string).

the error means type mismatch:

in case fragtrans refers native fragment support while workerfragment fragment support package. check import. using mixed imports fragment support package , native one.

instead of

 android.app.fragmentmanager fm= getfragmentmanager(); 

you should use

fragmentmanager fm =  getsupportfragmentmanager(); 

Comments