Take a Class Extending Fragemnt
class ExampleFragment extends Fragment { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) { View v = inflater.inflate(R.layout.dates_carusel_item, null); return v; }
And in your PagerAdapter do it
private class DatesPagerAdapter extends FragmentPagerAdapter { public DatesPagerAdapter(FragmentManager fm) { super(fm); } @Override public Fragment getItem(int arg0) { ExampleFragment fragment=new ExampleFragment(); Bundle bundle=new Bunlde();
Regardless of which view you want to set, make it in the example fragment and add your viewPager
ViewPager pager=new ViewPager(this); pager.setAdapter(new DatesPagerAdapter); llContainer.addView(pager)
Add your ViewPager to the xml itself so that it is properly bound, otherwise you can set LayoutParams at runtime if its visibility error
android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_below="@id/view_contact_sub_nav"android:id="+id/view_contact_values_container" android:paddingLeft="10dip"> <android.support.v4.view.ViewPager android:id="@+id/imagesgallery" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
source share