java - Incompatible types: DetailOneFragment cannot be converted to Fragment -
i have problem in code
error
incompatible types: detailonefragment cannot converted fragment in android
incompatible types: detailtwofragment cannot converted fragment in android
which wrong?
this detailactivity.java
import android.content.intnet; import android.os.bundle; import android.support.design.widget.floatingactionbutton; import android.support.design.widget.tablayout; import android.support.v4.app.fragmentmanager; import android.support.v4.view.viewpager; import android.support.v7.app.appcompatactivity; import android.view.view; import android.widget.imageview; import android.widget.textview; import org.adnroidtown.albaplanet.r; import org.adnroidtown.albaplanet.review_view.review1activity; public class detailactivity extends appcompatactivity { viewpager pager; tablayout tablayout; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_detail); //메인 액티비티에서 넘겨받은 인텐트 -시작- imageview iv = (imageview) findviewbyid(r.id.detail_img); textview tvname = (textview) findviewbyid(r.id.detail_store); intent intent = getintent(); iv.setimageresource(intent.getintextra("img", 0)); tvname.settext(intent.getstringextra("name")); pager = (viewpager) findviewbyid(r.id.detail_viewpager); tablayout = (tablayout) findviewbyid(r.id.tab_layout); fragmentmanager manager = getsupportfragmentmanager(); pageradapter adapter = new pageradapter(manager); pager.setadapter(adapter); tablayout.setupwithviewpager(pager); // mtablayout.setupwithviewpager(mpager1); pager.addonpagechangelistener(new tablayout.tablayoutonpagechangelistener(tablayout)); tablayout.settabsfrompageradapter(adapter); floatingactionbutton fab = (floatingactionbutton) findviewbyid(r.id.fab); fab.setonclicklistener(new view.onclicklistener() {@override public void onclick(view view) { intent intent = new intent(detailactivity.this, review1activity.class); startactivity(intent); } }); } }
this pageradapter.java
import android.support.v4.app.fragment; import android.support.v4.app.fragmentmanager; import android.support.v4.app.fragmentstatepageradapter; public class pageradapter extends fragmentstatepageradapter { public pageradapter(fragmentmanager fm) { super(fm); } @override public fragment getitem(int position) { fragment frag = null; switch (position) { case 0: frag = new detailonefragment(); break; case 1: frag = new detailtwofragment(); break; } return frag; } @override public int getcount() { return 2; } @override public charsequence getpagetitle(int position) { string title = " "; switch (position) { case 0: title = "game"; break; case 1: title = "movie"; break; } return title; } }
this detailonefragment.java
import android.app.fragment; import android.os.bundle; import android.view.layoutinflater; import android.view.view; import android.view.viewgroup; import org.adnroidtown.albaplanet.r; public class detailonefragment extends fragment { public detailonefragment(){ // required empty public constructor } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { // inflate layout fragment return inflater.inflate(r.layout.fragment_detail_one, container, false); } }
this error screenshot
replace
import android.app.fragment;
with
import android.support.v4.app.fragment;
in fragments
Comments
Post a Comment