java - Two Fragments Displayed Inside a Fragment(Page) -


i trying display 2 fragments 'leftfrag' , rightfrag, in 1 of viewpager's pages through myfragmentpageradapter. in case 0 new fragment instantiated androidfragment inside particular page, i'd display 2 fragments leftfrag , rightfrag. tried creating xml inflate not main contain 2 fragments got errors no views. particularity lost @ this.

mainactivity

public class mainactivity extends sherlockfragmentactivity implements actionbar.tablistener { ... setcontentview(r.layout.main); //got confused xml  myfragmentpageradapter fragmentpageradapter = new myfragmentpageradapter(fm, this); ... } 

myfragmentpageradapter

public class myfragmentpageradapter extends fragmentpageradapter{ @override     public fragment getitem(int arg0) {          switch(arg0){             /** android tab selected */             case 0:                 androidfragment androidfragment = new androidfragment();                 androidfragment.afragment(mcontext);                 return androidfragment; } 

androidfragment

public class androidfragment extends sherlockfragment{     public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) {           view rootview = inflater.inflate(r.layout.main, container, false);              //i trying replace or add 2 fragments in main.xml see xml below           final int margin = 16;         leftfrag = new roundedcolourfragment(getresources().getcolor(                 r.color.android_green), 1f, margin, margin / 2, margin, margin);          rightfrag = new roundedcolourfragment(getresources().getcolor(                 r.color.honeycombish_blue), 2f, margin / 2, margin, margin,                 margin);           //should use replace?          //ft.replace(r.id.fragg, leftfrag, "left");          //ft.replace(r.id.fragg2, rightfrag, "right");          fragmenttransaction ft = getchildfragmentmanager().begintransaction();          ft.add(r.id.fragg, leftfrag, "left");          ft.add(r.id.fragg2, rightfrag, "right");          ft.addtobackstack(null);          ft.commit(); } 

main.xml

<linearlayout xmlns:android="http://schemas.android.com/apk/res/android"     android:id="@+id/root"     android:orientation="horizontal"     android:layout_width="fill_parent"     android:layout_height="fill_parent" >       <framelayout               android:id="@+id/fragg"             android:layout_weight="2"             android:layout_width="match_parent"             android:layout_height="match_parent" />        <framelayout              android:id="@+id/fragg2"             android:layout_weight="2"             android:layout_width="match_parent"             android:layout_height="match_parent" />  <android.support.v4.view.viewpager         android:id="@+id/pager"         android:layout_width="wrap_content"         android:layout_height="wrap_content"     />  </linearlayout> 

roundedcolourfragment

public class roundedcolourfragment extends sherlockfragment {      private view mview;     private int mcolour;     private float mweight;     private int marginleft, marginright, margintop, marginbottom;      // need public empty constructor framework instantiate     public roundedcolourfragment() {      }      public roundedcolourfragment(int colour, float weight, int margin_left,             int margin_right, int margin_top, int margin_bottom) {         mcolour = colour;         mweight = weight;         marginleft = margin_left;         marginright = margin_right;         margintop = margin_top;         marginbottom = margin_bottom;     }      @override     public void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         mview = new view(getactivity());          gradientdrawable background = (gradientdrawable) getresources()                 .getdrawable(r.drawable.rounded_rect);         background.setcolor(mcolour);          mview.setbackgrounddrawable(background);         linearlayout.layoutparams lp = new linearlayout.layoutparams(0,                 layoutparams.fill_parent, mweight);         lp.setmargins(marginleft, margintop, marginright, marginbottom);         mview.setlayoutparams(lp);     }      @override     public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         return mview;     }  } 


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -