Android - Adding tabs to a Fragment -


i making fragment tabs having problem cannot resolve. when adding tabs must set content setcontent() can set activity or layout , want make transaction between 2 fragments. have exception:

java.lang.illegalargumentexception: must specify way create tab content         @ android.widget.tabhost.addtab(tabhost.java:225)         @ com.rpstudios.pokecooker.customfragment.oncreateview(customfragment.java:27)         @ android.support.v4.app.fragment.performcreateview(fragment.java:1504)         @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:942)         @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1121)         @ android.support.v4.app.backstackrecord.run(backstackrecord.java:682)         @ android.support.v4.app.fragmentmanagerimpl.execpendingactions(fragmentmanager.java:1484)         @ android.support.v4.app.fragmentmanagerimpl$1.run(fragmentmanager.java:450)         @ android.os.handler.handlecallback(handler.java:733)         @ android.os.handler.dispatchmessage(handler.java:95)         @ android.os.looper.loop(looper.java:136)         @ android.app.activitythread.main(activitythread.java:5105)         @ java.lang.reflect.method.invokenative(native method)         @ java.lang.reflect.method.invoke(method.java:515)         @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:792)         @ com.android.internal.os.zygoteinit.main(zygoteinit.java:608)         @ dalvik.system.nativestart.main(native method) 

here code throwing exception:

fragmenttabhost mtabhost;  @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle save){      view rootview = inflater.inflate(r.layout.tabhost_layout, container, false);       mtabhost = (fragmenttabhost) rootview.findviewbyid(android.r.id.tabhost);     mtabhost.setup(getactivity(), getchildfragmentmanager(), r.id.realtabcontent);      mtabhost.addtab(mtabhost.newtabspec("tab1").setindicator("tab1"));     mtabhost.addtab(mtabhost.newtabspec("tab2").setindicator("tab2"));     mtabhost.addtab(mtabhost.newtabspec("tab3").setindicator("tab3"));      mtabhost.setontabchangedlistener(new tabhost.ontabchangelistener() {         @override         public void ontabchanged(string s) {             if(s.equals("tab1")){              }else if(s.equals("tab2")){              }else if(s.equals("tab2")){              }         }     });       return rootview; } 

and here tabhost_layout.xml :

<android.support.v4.app.fragmenttabhost     xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@android:id/tabhost"     android:layout_width="match_parent"     android:layout_height="match_parent">      <linearlayout         android:orientation="vertical"         android:layout_width="match_parent"         android:layout_height="match_parent">          <framelayout             android:id="@+id/realtabcontent"             android:layout_width="match_parent"             android:layout_height="0dp"             android:layout_weight="1"/>      </linearlayout> </android.support.v4.app.fragmenttabhost> 

according jesse's answer:

you should add tab this:

mtabhost.addtab(mtabhost.newtabspec("explore").setindicator("explore", getresources().getdrawable(r.drawable.exploreicon)), theassociatedfragmenttab.class, null); 

and need explorerfragment class overrides oncreateview , inflates layout explorer tab:

@override public view oncreateview(layoutinflater inflater, viewgroup container,  bundle savedinstancestate)  {   super.oncreateview(inflater, container, savedinstancestate);   return inflater.inflate(r.layout.explorer_fragment, container,false); } 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

python - build a suggestions list using fuzzywuzzy -