android - Start a ListFragment from Activity -
i developing app present map (using fragment) , list (using listfragment). so, have activity starts application mapfragment or list fragment, according the user's preferences. can replace current activity mapfragment fragmentmanager , fragmenttransaction. problem have how can call or start listfragment activity. listfragment uses listviewadapter class inflate customized layout (repetedly different information) if want use transaction, necessary use listview container in layout. problem using layout items , not container.
any ideas solve problem or other way deal starting presenting listfragment in activity?
if trying display 2 different fragments @ same time, have @ documentation, basic idea include multiple framelayout
s in activity layout. don't forget view.setvisibility()
listfragments started same other fragment.
for example:
getsupportfragmentmanager().begintransaction() .replace(r.id.content_frame, new mylistfragment() .commit();
a more verbose example:
protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); findviewbyid(r.id.plusbutton).setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { getsupportfragmentmanager().begintransaction() .replace(r.id.content_frame, new mylistfragment()) .commit(); } }); }
activity_main.xml
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin" android:paddingbottom="@dimen/activity_vertical_margin" tools:context=".mainactivity"> <framelayout android:id="@+id/content_frame" android:clickable="true" android:layout_width="match_parent" android:layout_height="match_parent"/> <button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignparentbottom="true" android:layout_alignparentend="true" android:layout_alignparentright="true" android:text="press list" android:id="@+id/plusbutton" android:layout_gravity="center"/> </relativelayout>
Comments
Post a Comment