android - TabSpec SetContent to Fragment -
i using tabhost inside fragment create tabs. problem run tabspec's setcontent()
. need set nests fragment under <framelayout>
.
do uses getchildfragmentmanager()
this? how do so?
xml layout:
<linearlayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <tabwidget android:id="@android:id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0" android:orientation="horizontal" /> <framelayout android:id="@android:id/tabcontent" android:layout_width="match_parent" android:layout_height="0dp"/> <framelayout android:id="@+id/following" android:layout_width="fill_parent" android:layout_height="fill_parent"/> <framelayout android:id="@+id/you" android:layout_width="fill_parent" android:layout_height="fill_parent"/> </linearlayout>
fragment class:
public class activityfragment extends fragment implements tabhost.ontabchangelistener { private static final string following_spec = "following"; private static final string you_spec = "you"; private tabhost tabhost; public activityfragment(){} @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_activity, container, false); tabhost = (tabhost)view.findviewbyid(android.r.id.tabhost); tabhost.setup(); tabhost.tabspec followingspec = tabhost.newtabspec(following_spec); followingspec.setindicator("following"); followingspec.setcontent(); // <===need set content fragment tabhost.tabspec youspec = tabhost.newtabspec(you_spec); youspec.setindicator("you"); tabhost.addtab(followingspec); tabhost.addtab(youspec); tabhost.setcurrenttab(0); return view; } @override public void ontabchanged(string s) { } }
here's answer. mixing android's tabhost support library's fragmenttabhost. 2 different things!
public class activityfragment extends fragment implements tabhost.ontabchangelistener { private static final string following_spec = "following"; private static final string you_spec = "you"; private fragmenttabhost tabhost; public activityfragment(){} @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view view = inflater.inflate(r.layout.fragment_activity, container, false); tabhost = (fragmenttabhost)view.findviewbyid(r.id.tabhost); tabhost.setup(getactivity(), getchildfragmentmanager(), android.r.id.tabcontent); tabhost.addtab(tabhost.newtabspec(following_spec).setindicator("following"), followingactivityfragment.class, null); tabhost.addtab(tabhost.newtabspec(you_spec).setindicator("you"), youactivityfragment.class, null); tabhost.setcurrenttab(0); return view; } @override public void ontabchanged(string s) { } }
Comments
Post a Comment