Android Open Source - SwitchTabs Sections Pager Adapter






From Project

Back to project page SwitchTabs.

License

The source code is released under:

Apache License

If you think the Android project SwitchTabs 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.normal.testdemo.adapters;
//from  www  .ja v  a 2s  .co m
import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.util.Log;
import com.normal.testdemo.R;
import com.normal.testdemo.activitys.MainActivity;
import com.normal.testdemo.fragments.PlaceholderFragment;

import java.util.Locale;

/**
 * Created by ex_chenjinghao on 2014/4/8.
 * This Adapter is the controller of PlaceholderFragment.
 */
public class SectionsPagerAdapter extends FragmentPagerAdapter {
  private Context context = MainActivity.context;

  public SectionsPagerAdapter(FragmentManager fm) {
    super(fm);
  }

  @Override
  public Fragment getItem(int position) {
    // getItem is called to instantiate the fragment for the given page.
    // Return a PlaceholderFragment (defined as a static inner class
    // below).
    switch (position){
      case 0:
        Log.i("1","fragment1 Created");
        return PlaceholderFragment.newInstance(position + 1);
      case 1:
        Log.i("2","fragment2 Created");
        return PlaceholderFragment.newInstance(position + 1);
      case 2:
        Log.i("3","fragment3 Created");
        return PlaceholderFragment.newInstance(position + 1);
    }
    return null;
  }

  @Override
  public int getCount() {
    // Show 3 total pages.
    // ?????3?tab??????4?????tab?????
    return 3;
  }

  @Override
  public CharSequence getPageTitle(int position) {
    // ????????
    Locale l = Locale.getDefault();
    switch (position) {
      case 0:
        return context.getString(R.string.title_section1).toUpperCase(l);
      case 1:
        return context.getString(R.string.title_section2).toUpperCase(l);
      case 2:
        return context.getString(R.string.title_section3).toUpperCase(l);
    }
    return null;
  }
}




Java Source Code List

com.normal.testdemo.activitys.MainActivity.java
com.normal.testdemo.activitys.SplashActivity.java
com.normal.testdemo.adapters.HotelListAdapter.java
com.normal.testdemo.adapters.SectionsPagerAdapter.java
com.normal.testdemo.beans.Hotel.java
com.normal.testdemo.beans.Hotels.java
com.normal.testdemo.fragments.PlaceholderFragment.java
com.normal.testdemo.utils.AsynImageLoader.java
com.normal.testdemo.utils.Utils.java
com.normal.testdemo.view.XListViewFooter.java
com.normal.testdemo.view.XListViewHeader.java
com.normal.testdemo.view.XListView.java