Android Open Source - AndroidAdvancedDemos View Pager Fragment






From Project

Back to project page AndroidAdvancedDemos.

License

The source code is released under:

MIT License

If you think the Android project AndroidAdvancedDemos listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.krieger.training.androidadvanceddemos.fragment;
/*  w  w  w  .  j av a2 s.c  o  m*/
import java.util.ArrayList;
import java.util.List;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.essentailab.training.androidadvanceddemos.R;
import com.krieger.training.androidadvanceddemos.entities.ImageElement;

public class ViewPagerFragment extends Fragment{
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState){
    List<ImageElement> gallery = new ArrayList<ImageElement>();
    gallery.add(new ImageElement("Image 1", "http://www.krieger-electronics.com/images/carousel%20(1).jpg"));
    gallery.add(new ImageElement("Image 2", "http://www.krieger-electronics.com/images/carousel%20(2).jpg"));
    gallery.add(new ImageElement("Image 3", "http://www.krieger-electronics.com/images/carousel%20(3).jpg"));
    gallery.add(new ImageElement("Image 4", "http://www.krieger-electronics.com/images/carousel%20(4).jpg"));
    gallery.add(new ImageElement("Image 5", "http://www.krieger-electronics.com/images/carousel%20(5).jpg"));
    
    View view = inflater.inflate(R.layout.fragment_gallery, container, false);
    ViewPager mPager = (ViewPager) view.findViewById(R.id.gallery_pager);
    PagerAdapter mPagerAdapter = new GalleryPagerAdapter(
        getChildFragmentManager(), gallery);
    mPager.setAdapter(mPagerAdapter);
    return view;
  }
  
  private class GalleryPagerAdapter extends FragmentPagerAdapter {
    private List<ImageElement> urls;
    
    public GalleryPagerAdapter(FragmentManager fm, List<ImageElement> urls) {
      super(fm);
      this.urls = urls;
    }
    
    @Override
    public Fragment getItem(int position) {
      return GalleryPageFragment.create(position, urls.get(position)
          .getUrl());
    }
    
    @Override
    public int getCount() {
      return urls.size();
    }
  }
}




Java Source Code List

com.krieger.training.androidadvanceddemos.HomeActivity.java
com.krieger.training.androidadvanceddemos.adapter.SimpleListAdapter.java
com.krieger.training.androidadvanceddemos.adapter.UniversalListAdapter.java
com.krieger.training.androidadvanceddemos.entities.DrawerItem.java
com.krieger.training.androidadvanceddemos.entities.HeadedList.java
com.krieger.training.androidadvanceddemos.entities.ImageDownloaderCookie.java
com.krieger.training.androidadvanceddemos.entities.ImageElement.java
com.krieger.training.androidadvanceddemos.entities.ListElementCookie.java
com.krieger.training.androidadvanceddemos.fragment.AsyncTaskFragment.java
com.krieger.training.androidadvanceddemos.fragment.ErrorFragment.java
com.krieger.training.androidadvanceddemos.fragment.GalleryPageFragment.java
com.krieger.training.androidadvanceddemos.fragment.GridViewFragment.java
com.krieger.training.androidadvanceddemos.fragment.ListFragment.java
com.krieger.training.androidadvanceddemos.fragment.NestedFragment.java
com.krieger.training.androidadvanceddemos.fragment.SimpleFragment.java
com.krieger.training.androidadvanceddemos.fragment.ViewPagerFragment.java
com.krieger.training.androidadvanceddemos.interfaces.AdapterCommand.java
com.krieger.training.androidadvanceddemos.interfaces.AsyncListInflationAction.java
com.krieger.training.androidadvanceddemos.interfaces.ListHeaderInflationAction.java
com.krieger.training.androidadvanceddemos.interfaces.ListItemInflationAction.java
com.krieger.training.androidadvanceddemos.io.ImageDownloaderAsyncTask.java
com.krieger.training.androidadvanceddemos.listener.ListOnItemClickListener.java