The app for tablet for each screen into four parts(four fragment). I have added four fragment to fragments transaction in a single layout. Now I have to implement view pager in that. How can I achieve that. Using that view pager library I have to pass the fragment manager and fragmentlist as argument. In my scenario How can I pass every 4 argument in a single time?
My Main Activity was:
> public void onCreate(Bundle savedInstanceState) {
> super.onCreate(savedInstanceState);
> setContentView(R.layout.activity_main); NewsFragment[]
> newsFragment_obj = new NewsFragment[GlobalValues.titile.length];
>
> fragMentTra = getFragmentManager().beginTransaction();
>
> for (int i = 0; i < GlobalValues.titile.length; i++) {
> newsFragment_obj[i] = new NewsFragment(GlobalValues.titile[i],
> GlobalValues.content[i]); }
>
> fragMentTra.add(R.id.fragment_container1, newsFragment_obj[0],
> "Fragment1"); fragMentTra.add(R.id.fragment_container2, newsFragment_obj[1],
> "Fragment2"); fragMentTra.add(R.id.fragment_container3, newsFragment_obj[2],
> "Fragment3"); fragMentTra.add(R.id.fragment_container4, newsFragment_obj[3],
> "Fragment4");
>
> fragMentTra.commit(); }
This is how I have added the four fragment to the screen. Now only am looking into view pager. So could you please tell me how can I achieve that with view pager with example code.
My XML File was:
<LinearLayout
android:id="@+id/upper"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/up_left_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ffff66" >
<FrameLayout
android:id="@+id/fragment_container1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/up_right_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#ccffff" >
<FrameLayout
android:id="@+id/fragment_container2"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/lower"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<LinearLayout
android:id="@+id/down_left_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#66cc33" >
<FrameLayout
android:id="@+id/fragment_container3"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/down_right_area"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:background="#cc6600" >
<FrameLayout
android:id="@+id/fragment_container4"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>
</LinearLayout>