java - Android Tab View unable to getIntent() -
i trying tab in android project. here tab main page:
public class eventdetailmain extends fragmentactivity { context context = this; viewpager tab; eventdtltabpageradapter tabadapter; actionbar actionbar; @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.event_detail_main); tabadapter = new eventdtltabpageradapter(getsupportfragmentmanager()); tab = (viewpager) findviewbyid(r.id.pager); tab.setonpagechangelistener(new viewpager.simpleonpagechangelistener() { @override public void onpageselected(int position) { actionbar = getactionbar(); actionbar.setselectednavigationitem(position); } }); tab.setadapter(tabadapter); actionbar = getactionbar(); // enable tabs on action bar actionbar.setnavigationmode(actionbar.navigation_mode_tabs); actionbar.tablistener tablistener = new actionbar.tablistener() { public void ontabreselected(android.app.actionbar.tab tab, android.app.fragmenttransaction ft) { } public void ontabselected(android.app.actionbar.tab tab, android.app.fragmenttransaction ft) { // on tab selected show respected fragment view tab.setcurrentitem(tab.getposition()); } public void ontabunselected(android.app.actionbar.tab tab, android.app.fragmenttransaction ft) { } }; // add together new tab actionbar.addtab(actionbar.newtab().settext("event detail") .settablistener(tablistener)); actionbar.addtab(actionbar.newtab().settext("chat room") .settablistener(tablistener)); actionbar.addtab(actionbar.newtab().settext("drop review") .settablistener(tablistener)); }
and content of first tab:
public class eventdetail extends fragment { context context; view eventdetail; @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { eventdetail = inflater.inflate(r.layout.event_detail, container, false); context = this; intent = getintent(); event eventmodel = (event) i.getserializableextra("eventobj"); }
}
however, getting error message "type mismatch: cannot convert eventdetail context" @ context = , "the method getintent() undefined type eventdetail" @ getintent().
any ideas? because did not extends activity?
thanks in advance.
edit
i getting error message such:
11-13 20:24:49.634: e/androidruntime(16503): fatal exception: main 11-13 20:24:49.634: e/androidruntime(16503): java.lang.nullpointerexception 11-13 20:24:49.634: e/androidruntime(16503): @ android.support.v4.app.fragmentstatepageradapter.instantiateitem(fragmentstatepageradapter.java:116) 11-13 20:24:49.634: e/androidruntime(16503): @ android.support.v4.view.viewpager.addnewitem(viewpager.java:837) 11-13 20:24:49.634: e/androidruntime(16503): @ android.support.v4.view.viewpager.populate(viewpager.java:1053) 11-13 20:24:49.634: e/androidruntime(16503): @ android.support.v4.view.viewpager.populate(viewpager.java:919) 11-13 20:24:49.634: e/androidruntime(16503): @ android.support.v4.view.viewpager.onmeasure(viewpager.java:1441) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.view.measure(view.java:12892) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4698) 11-13 20:24:49.634: e/androidruntime(16503): @ android.widget.framelayout.onmeasure(framelayout.java:293) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.view.measure(view.java:12892) 11-13 20:24:49.634: e/androidruntime(16503): @ android.widget.linearlayout.measurevertical(linearlayout.java:812) 11-13 20:24:49.634: e/androidruntime(16503): @ android.widget.linearlayout.onmeasure(linearlayout.java:553) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.view.measure(view.java:12892) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.viewgroup.measurechildwithmargins(viewgroup.java:4698) 11-13 20:24:49.634: e/androidruntime(16503): @ android.widget.framelayout.onmeasure(framelayout.java:293) 11-13 20:24:49.634: e/androidruntime(16503): @ com.android.internal.policy.impl.phonewindow$decorview.onmeasure(phonewindow.java:2257) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.view.measure(view.java:12892) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1240) 11-13 20:24:49.634: e/androidruntime(16503): @ android.view.viewrootimpl.handlemessage(viewrootimpl.java:2628) 11-13 20:24:49.634: e/androidruntime(16503): @ android.os.handler.dispatchmessage(handler.java:99) 11-13 20:24:49.634: e/androidruntime(16503): @ android.os.looper.loop(looper.java:137) 11-13 20:24:49.634: e/androidruntime(16503): @ android.app.activitythread.main(activitythread.java:4512) 11-13 20:24:49.634: e/androidruntime(16503): @ java.lang.reflect.method.invokenative(native method) 11-13 20:24:49.634: e/androidruntime(16503): @ java.lang.reflect.method.invoke(method.java:511) 11-13 20:24:49.634: e/androidruntime(16503): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:982) 11-13 20:24:49.634: e/androidruntime(16503): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:749) 11-13 20:24:49.634: e/androidruntime(16503): @ dalvik.system.nativestart.main(native method)
yes. in fragment have getactivity(). there can utilize getintent().
edit so: first error - context = this; should context = getactivity(); sec error - getintent() should getactivity().getintent();
edit2: have 3rd error :d need homecoming view :
return eventdetail;
and also, not using eventmodel anywhere.
java android view tabs
No comments:
Post a Comment