android - layout with fragment and framelayout replaced by another fragment and framelayout -
edit:
so after comments below, revisted , realized hanging me up.
imagine client list , client details activity started :
public class clientsmainactivity extends fragmentactivity { @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); //studiotabopenhelper db; setcontentview(r.layout.main_client_activity); } }
so works great, starts main_client_activity (defined in layout below, , call activity when button on main screen clicked):
intent intent = new intent(getactivity(), clientsmainactivity.class); startactivity(intent);
easy issue is, clientsmainactivity
not call oncreateview or anything, sets layout layout defines fragment, , listfragment. fine cause not trying pass clientsmainactivity
, if have hypothetical activity like:
sessionmainsactivity
called when click on session edit of client, not calling sessionsmainactivity
same way (starts activity sets alayout), want layout set defines how fragments split up. want pass in data , subsequent fragments (like session clicked on editing/mucking with.
so wonder if above makes sense, sure simple thing cannot wrap brain around. have no issues calling fragmentactivitie
s other fragments, take whole screen works. guess big issue clientsmainactivity
example found online doing recipes shows how make multiple fragments screen. thing gets me fragmentactivity
sets content view, layout work seems, that's why cannot figure out how code same thing let me pass in values fragments layout defines etc...
end edit
so using nice little tutorial here:
http://developer.android.com/guide/topics/fundamentals/fragments.html
it has gotten me long way , utilizing main activity, , fragment_layout.xml, got nice client list on left (thats listfragment) , details fragment on right.
then added ability edit session information on client (or edit client details) both of full screen fragments. worked great.
now decided session edit ui best served splitting information 2 panes again.
this not working thought, said have main_activity in oncreate:
public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main_client_activity); }
with main_client_activity.xml
being defined in 2 layouts 1 landscape tablets here:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.viciousbytes.studiotab.subactivities.clientlistview" android:id="@+id/client_list" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" /> <framelayout android:id="@+id/client_details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" android:background="?android:attr/detailselementbackground"/> </linearlayout>
this works great! in case handled else full screen activity started own fragment:
editsessionactivity
editclientactiivyt
both of use getsupportfragmentmanager().begintransaction , pass information .newinstance call.
i had session_edit.xml
layout defined buttons, textviews etc..and working great. thats loaded in sessionedit
fragment "launched" editsessionactivity
since want split apart ran snag. above defined client_list , client_details id, these placeholders on screen? reference when wanna replace whats there totally different fragments?
or build fragment layout called fragment_session_layout defines like:
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent"> <fragment class="com.viciousbytes.studiotab.subactivities.sessionedit" android:id="@+id/session_edit" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" /> <framelayout android:id="@+id/invoice_details" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" android:background="?android:attr/detailselementbackground" /> </linearlayout>
sorry don't know title on tip of tongue of asking, how 2 panes of fragments twice over. demo online shows how 1 (and simple listfragment @ that).
i have done above , cannot figure out how pass fragment data need, using in editsessionactivity:
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); int clientid = getintent().getintextra(the_selected_client, -1); int sessionid = getintent().getintextra(selected_session,-1); sessionedit edits = sessionedit.newinstance(this.getbasecontext(), false, clientid, sessionid); muilistener = (onupdateui)edits; getsupportfragmentmanager().begintransaction().add(android.r.id.content, edits).commit(); }
that worked, try adhere earlier fragment example, assumed editsessionactivit
y sorta making mainactivity
(cause has 2 panels in main one). recoded oncreate
in editsessionactivity
this:
@override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.edit_session_fullview); }
which after fighting in editsession fragment dealing oncreateview, got work couldn't pass in data cause there no instantiation of object using previous oncreate
had edits=sessionedit.newinstance(...)
so practice doing other fragment layout has 2 pains in , starting when right action triggered. or 1 supposed replace 2 created fragments?? main_client_activity.xml
somehow?
i assume editing clients , editing sessions 2 distinct activities. when switch "editing clients" "editing sessions" mode, both "list" , "details" panes change?
i go 2 layout files, instead of trying reuse same layout , reload fragments in it.
if tried reuse same layout, have to:
- change
@+id/invoice_details
@+id/right_pane
. otherwise confusing load related sessions "invoice_details" placeholder. - replace fragment definition
framelayout
, load eitherclientlistview
orsessionlistview
(or it's called) fragment there @ runtime.
this add more complexity having layout xml file in opinion.
so
- take existing code works client list , client details
- duplicate involved parts, , change needs changed it's session list , session details
- remove duplication it's easy (common functions go utility classes, common layout elements layout includes). leave things hard de-duplicate as-is.
- re-evaluate later, when have more fragments, more layouts , more experience.
update, 2 different approaches fragments can embedded in activity
as android documentation states, there 2 main ways can fragment show in activity:
- declare fragment in layout's xml file (
<fragment class=.... />
) - put placeholder
framelayout
in layout's xml file , load fragment @ runtime
first approach fine when fragment doesn't need receive arguments. like, example, if logic retrieve single , list of clients hardcoded in fragment's code.
second approach lets pass arguments fragment, , therefore appropriate "details drilldown" type of fragments.
from updated question understand that,
- each client has separate list of sessions
- the components in play are:
editsessionactivity
hosts 2 fragments, 1 displaying list of sessions, displaying session details
if that's correct, indeed you'd need load both fragments programmatically because both needs parameters passed to. layout have 2 framelayout
s. editsessionactivity
start getting parameters intent ("which list of sessions working with?"), , load "list of sessions" fragment these parameters. when user selects list item in fragment, other fragment loaded session details.
Comments
Post a Comment