android - Trouble with ViewPager displaying Fragments -


i trying fragment 3 tabs displayed using viewpager. used instantiate fragment activity using fragmentmgr, worked fine. when converted navigation using viewpager, fragment no longer displayed.

mainactivity.java

when initiate fragment this, gets displayed. eg:

launchlistfragment fragment = new launchlistfragment(); fragment.newinstance(list_type); getsupportfragmentmanager().begintransaction()                 .add(r.id.item_detail_container,     fragment).commit(); 

i tried change above code make use of viewpager follows:

mviewpager = (viewpager) findviewbyid(r.id.pager); mviewpager.setadapter(new launchpageadapter(getsupportfragmentmanager(),list_type)); mviewpager.setcurrentitem(0); 

where launchpageadapter calls launchlistfragment.

launchpageadapter.java

public class launchpageadapter extends fragmentpageradapter { private static string select="";      public launchpageadapter(fragmentmanager fm, string type) {         super(fm);         select=type;     }      @override     public fragment getitem(int position) {         switch (position) {             case 0:                 return launchlistfragment.newinstance(select);             case 1:                 return addteamfragment.newinstance();          }         return null;     }      @override     public int getcount() {         // todo auto-generated method stub         return 2;     } 

here launchlistfragment.java

public class launchlistfragment extends listfragment implements actionbar.tablistener { public static  string list_type = "invalid"; genericlistdata g_data[] = null;      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);      }    @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view result = inflater.inflate(r.layout.fragment_launch_list,                 container, false);           setactiontabs();          setlist();         return (result);     }      public static fragment newinstance(string type) {     fragment frag = new launchlistfragment();     bundle args = new bundle();     list_type=type;     args.putstring(list_type, type);     frag.setarguments(args);     return (frag); } 

this main.xml layout used mainactivity

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools=  "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" tools:context=".mainactivity" >  <fragment     android:id="@+id/item_list"     android:name="com.teammanager.itemlistfragment"     android:layout_width="0dp"     android:layout_height="match_parent"     android:layout_weight="1"     tools:layout="@android:layout/list_content" />  <framelayout     android:id="@+id/item_detail_container"     android:layout_width="0dp"     android:layout_height="match_parent"     android:layout_weight="3" >      <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_width="match_parent"         android:layout_height="0dp"         android:layout_weight="1" /> </framelayout> 

fragment_launch_list.xml used launchlistfragment

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" >  <listview     android:id="@android:id/list"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_weight="1"     android:drawselectorontop="false" > </listview>  <textview     android:id="@+id/itemname"     android:layout_width="fill_parent"     android:layout_height="fill_parent"     android:layout_alignparentbottom="true"     android:layout_alignparenttop="true"     android:layout_marginbottom="5dp"     android:layout_margintop="5dp"     android:gravity="center_vertical"     android:textcolor="#000000"     android:textsize="22dp"     android:textstyle="bold" /> 

when debug this, can see launchlistfragment getting instantiated, oncreate , oncreate view called, won't displayed. :(

can here let me know if missing here in viewpager implementation?

update

when called launchlistfragment without using viewpager, set content view first , passed r.id.item_detail_container id of framelayout want fragment displayed. please refer main.xml earlier

 setcontentview(r.layout.main.xml);  launchlistfragment fragment = new launchlistfragment();  fragment.newinstance(list_type);   getsupportfragmentmanager().begintransaction()                 .add(r.id.item_detail_container,       fragment).commit(); 

when changed use viewpager, not sure i'm directing fragment displayed. in fragment onview i'm inflating fragment_launch_list , returning view. how view pager know set fragment view. inside id pager?

i'm absolute beginner, apologize if these naive questions.

cheers.

the question description suitable problem had. know question old may other face same. @geoplex have not shown code of launchpageadapter class. i'm not sure if solves problem or not. me worked.

in pageradapter, public boolean isviewfromobject(view view, object object) overridden. removed method , allowed superclass handle it. started giving expected result.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -