This does not work ViewPager. You load ViewPager pages with the PagerAdapter . Your ListView will be contained in the Snippet created by the PagerAdapter.
In the layout:
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/home_pannels_pager" />
In FragmentActivity with this layout:
ViewPager pager = (ViewPager) findViewById(R.id.viewPager);
pager.setAdapter(new PagerAdapter(getSupportFragmentManager()));
Example simle PagerAdapter:
public class PagerAdapter extends FragmentPagerAdapter {
public FrontPageAdapter(FragmentManager Fm) {
super(Fm);
}
@Override
public Fragment getItem(int position) {
Bundle arguments = new Bundle();
arguments.putInt("position", position);
FragmentPage fragment = new FragmentPage();
fragment.setArguments(arguments);
return fragment;
}
@Override
public int getCount() {
return 3;
}
}
FragmentPage example:
public class FragmentPage extends Fragment {
public FragmentPage() {}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_frontpage, container, false);
Bundle arguments = getArguments();
int position = b.getInt("position");
return view;
}
}
source
share