コード例 #1
0
 @Override
 public Fragment getItem(int pos) {
   switch (pos) {
     case 0:
       return FirstFragment.newInstance("FirstFragment, Instance 1");
     case 1:
       return SecondFragment.newInstance("SecondFragment, Instance 1", 1);
     case 2:
       return ThirdFragment.newInstance("ThirdFragment, Instance 1");
     case 3:
       return FourFragment.newInstance("FourFragment, Instance 2");
       // case 4: return FourFragment.newInstance("FourFragment, Instance 2");
     default:
       return null;
   }
 }
コード例 #2
0
  @Override
  public void onPageSelected(int position) {

    if (position - 1 == prevPage) {
      Log.i("Swipped", "Swipped Left");
      // Toast.makeText(getApplicationContext(), "Swipped Left"+position, Toast.LENGTH_LONG).show();
    }
    // went up a page
    if (position + 1 == prevPage) {
      Log.i("Swipped", "Swipped Right");
      // Toast.makeText(getApplicationContext(),"Swipped Right"+position,Toast.LENGTH_LONG).show();
    }
    prevPage = position;

    if (position == 0) {

      FirstFragment.newInstance("FirstFragment, Instance 1");
      // Toast.makeText(getApplicationContext(),"Hello",Toast.LENGTH_LONG).show();
    }
    if (position == 1) {
      SecondFragment.newInstance("SecondFragment, Instance 1", 1);
      // Toast.makeText(getApplicationContext(),"Hello1",Toast.LENGTH_LONG).show();
    }
    if (position == 2) {
      ThirdFragment.newInstance("ThirdFragment, Instance 1");
      // Toast.makeText(getApplicationContext(),"Hello2",Toast.LENGTH_LONG).show();
    }
    if (position == 3) {
      FourFragment.newInstance("FourFragment, Default");
      // Toast.makeText(getApplicationContext(),"Hello3",Toast.LENGTH_LONG).show();
    }

    for (int i = 0; i < dotsCount; i++) {
      // dots[i].setTextColor(getResources().getColor(android.R.color.darker_gray));
      dots[i].setImageResource(R.drawable.tour_position_inactive);
    }
    // dots[position].setTextColor(getResources().getColor(R.color.white));

    dots[position].setImageResource(R.drawable.tour_position_active);
    if (position == 3) {
      dotsLayout.setVisibility(View.GONE);
    } else {
      dotsLayout.setVisibility(View.VISIBLE);
    }
  }