Sunday, 15 February 2015

android - Activity with fragments crashes like if it were nested fragments -



android - Activity with fragments crashes like if it were nested fragments -

i guess knows project created when take "master detail flow" when creating project in eclipse.

theres layouts left side, right side , two_pane layout fragment , framelayout fragment container. works fine.

now have 'main' activity viewpager, fragments etc., , phone call activity fragment callback. activity start new activity b. activity b set illustration activity eclipse talked about.

now have problem app crashes

error/androidruntime(8105): caused by: java.lang.illegalargumentexception: binary xml file line #57: duplicate id 0x7f080024, tag null, or parent id 0x0 fragment fragmentnumber3

when replace fragment in two_pane layout framelayout, doesn't crash. problem typical nested fragments, don't have nested fragments here, right? have activity b that, @ point, doesn't have activity a.

what's problem here?

edit: activity b:

public class sucheactivity extends fragmentactivity implements searchboxfragment.searchboxlistener {

private boolean mtwopane; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.searchbox); getactionbar().setdisplayhomeasupenabled(true); if (findviewbyid(r.id.searchresult_container) != null) { mtwopane = true; } } }

and thats two_pane layout activity, searchbox should left, searchresults right:

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginleft="16dp" android:layout_marginright="16dp" android:baselinealigned="false" android:divider="?android:attr/dividerhorizontal" android:orientation="horizontal" android:showdividers="middle" > <fragment android:id="@+id/searchbox_fragment" android:name="com.example.layouttest.searchboxfragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1"/> <framelayout android:id="@+id/searchresult_container" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" /> </linearlayout>

heres searchboxfragment class:

public class searchboxfragment extends fragment { searchboxlistener mcallback; view v; public interface searchboxlistener { public void onsearchstarted(); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { v = inflater.inflate(r.layout.searchbox, container, false); homecoming v; } }

the searchresultfragment:

public class searchresultfragment extends fragment { public searchresultfragment() { } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { homecoming inflater.inflate(r.layout.searchresult, container, false); } @override public void onviewcreated(view view, bundle savedinstancestate) { super.onviewcreated(view, savedinstancestate); } }

and refs.xml in res/values-large:

<resources> <item name="searchbox" type="layout">@layout/haussuche_twopane</item> </resources>

okay, found out:

i cant set layout of activity searchbox.xml (and have alias'd in refs.xml two_pane.xml) , set layout of searchboxfragment searchbox.xml.

i thought searchbox.xml never shown activity in two-pane-mode, safely set elsewhere, that's wrong.

what did re-create layout , utilize searchbox_onepane.xml , searchbox_twopane.xml.

android android-fragments

No comments:

Post a Comment