i'm creating menu has 2 tabs. each tab has 3 fragments show content. though straightforward after experimenting , googling looks wrong.
i managed create fragments first tab. however, when change other tab , back, following error message , app crashes:
07-11 16:49:57.829: e/androidruntime(20009): fatal exception: main 07-11 16:49:57.829: e/androidruntime(20009): android.view.inflateexception: binary xml file line #8: error inflating class fragment 07-11 16:49:57.829: e/androidruntime(20009): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:697) 07-11 16:49:57.829: e/androidruntime(20009): @ android.view.layoutinflater.rinflate(layoutinflater.java:739) 07-11 16:49:57.829: e/androidruntime(20009): @ android.view.layoutinflater.inflate(layoutinflater.java:489) 07-11 16:49:57.829: e/androidruntime(20009): @ android.view.layoutinflater.inflate(layoutinflater.java:396) 07-11 16:49:57.829: e/androidruntime(20009): @ com.machinedata.ui.feedback.usersfragment.oncreateview(usersfragment.java:16) 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:828) 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1032) 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.backstackrecord.run(backstackrecord.java:622) 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1382) 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.fragmentmanagerimpl$1.run(fragmentmanager.java:426) 07-11 16:49:57.829: e/androidruntime(20009): @ android.os.handler.handlecallback(handler.java:605) 07-11 16:49:57.829: e/androidruntime(20009): @ android.os.handler.dispatchmessage(handler.java:92) 07-11 16:49:57.829: e/androidruntime(20009): @ android.os.looper.loop(looper.java:137) 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.activitythread.main(activitythread.java:4507) 07-11 16:49:57.829: e/androidruntime(20009): @ java.lang.reflect.method.invokenative(native method) 07-11 16:49:57.829: e/androidruntime(20009): @ java.lang.reflect.method.invoke(method.java:511) 07-11 16:49:57.829: e/androidruntime(20009): @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:978) 07-11 16:49:57.829: e/androidruntime(20009): @ com.android.internal.os.zygoteinit.main(zygoteinit.java:745) 07-11 16:49:57.829: e/androidruntime(20009): @ dalvik.system.nativestart.main(native method) 07-11 16:49:57.829: e/androidruntime(20009): caused by: java.lang.illegalargumentexception: binary xml file line #8: duplicate id 0x7f0b0013, tag null, or parent id 0xffffffff fragment com.machinedata.ui.userlistfragment 07-11 16:49:57.829: e/androidruntime(20009): @ android.app.activity.oncreateview(activity.java:4252) 07-11 16:49:57.829: e/androidruntime(20009): @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:673)
now tabs fragments themselves, placed dynamically screen. these fragments inflate xml-files have fragments placed in them statically. after googling found out placing fragments inside fragments bit tricky.
getchildfragmentmanager works in api level 17, i'd keep api level in 14. there anyway create kind of menu structure? need create separate activities tabs?
here activity displays tabs:
public class feedbackactivity extends activity implements userlistfragment.onitemclickedlistener { private toplistsfragment toplist; private usersfragment users; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); final actionbar actionbar = getactionbar(); actionbar.setnavigationmode(actionbar.navigation_mode_tabs); setcontentview(r.layout.feedback_screen); //create tabs dashboard , graphs actionbar.tab tab1 = actionbar.newtab().settext(r.string.feedbackusers); actionbar.tab tab2 = actionbar.newtab().settext(r.string.feedbacktoplist); toplist = new toplistsfragment(); users = new usersfragment(); tab2.settablistener(new mytabslistener(toplist)); tab1.settablistener(new mytabslistener(users)); actionbar.addtab(tab1); actionbar.addtab(tab2); } @override public void oncreatecontextmenu(contextmenu menu, view v, contextmenuinfo menuinfo) { // todo auto-generated method stub super.oncreatecontextmenu(menu, v, menuinfo); } @override public boolean oncreateoptionsmenu(menu menu) { // todo auto-generated method stub return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // todo auto-generated method stub log.v("log","id: " + item.getitemid() + " " + item.gettitle()); switch (item.getitemid()) { case android.r.id.home: intent intent = new intent(this, modeselectactivity.class); startactivity(intent); return true; default: return super.onoptionsitemselected(item); } } @override public void onuseritemclick(adapterview<?> parent, view v, int position, long id, userdata user) { //wite activity code here log.v("log", "name: " + user.getname()); } //tablistener class mytabslistener implements actionbar.tablistener { public fragment fragment; public mytabslistener(fragment fragment) { this.fragment = fragment; } @override public void ontabreselected(tab tab, fragmenttransaction ft) { } @override public void ontabselected(tab tab, fragmenttransaction ft) { ft.replace(r.id.feedback_fragcontainer, fragment); } @override public void ontabunselected(tab tab, fragmenttransaction ft) { ft.remove(fragment); } } }
its xml-file:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <linearlayout android:id="@+id/feedback_fragcontainer" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" /> </linearlayout>
and tab-fragment's xml:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" android:baselinealigned="false"> <fragment android:id="@+id/feedbackuserlistfragment" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="match_parent" class="com.machinedata.ui.userlistfragment" > </fragment> <fragment android:id="@+id/feedbacksessionlistfragment" android:layout_width="match_parent" android:layout_weight="1" android:layout_height="match_parent" class="com.machinedata.ui.feedback.sessionlistfragment" > <!-- preview: layout=@layout/details --> </fragment> <fragment android:id="@+id/feedbackdetailsfragment" android:layout_width="match_parent" android:layout_weight="0.5" android:layout_height="match_parent" class="com.machinedata.ui.feedback.detailsfragment" > <!-- preview: layout=@layout/details --> </fragment> </linearlayout>
to honest, i'm not sure error message means duplicate id, or causes it. i'm looking solution either create menu structure described or way fix current implementation.
nested fragment functionality (implemented on api level 17) provided in support package too. extend fragment android.support.v4.app.fragment
instead of android.app.fragment
. , replace parent activity android.support.v4.app.fragmentactivity
.
Comments
Post a Comment