Android Open Source - iTunesAndroidPreview Main Activity






From Project

Back to project page iTunesAndroidPreview.

License

The source code is released under:

GNU General Public License

If you think the Android project iTunesAndroidPreview 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.besaba.srmu;
/*from   w ww  .j  ava 2  s.co  m*/
import com.besaba.srmu.adapter.TabsPagerAdapter;
import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;
import com.besaba.srmu.R;

public class MainActivity extends FragmentActivity implements
    ActionBar.TabListener {

  private ViewPager viewPager;
  private TabsPagerAdapter mAdapter;
  private ActionBar actionBar;
  // Tab titles
  private String[] tabs = { "Search", "About" };

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Initilization
    viewPager = (ViewPager) findViewById(R.id.pager);
    actionBar = getActionBar();
    mAdapter = new TabsPagerAdapter(getSupportFragmentManager());

    viewPager.setAdapter(mAdapter);
    actionBar.setHomeButtonEnabled(false);
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);    

    // Adding Tabs
    for (String tab_name : tabs) {
      actionBar.addTab(actionBar.newTab().setText(tab_name)
          .setTabListener(this));
    }

    /**
     * on swiping the viewpager make respective tab selected
     * */
    viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

      @Override
      public void onPageSelected(int position) {
        // on changing the page
        // make respected tab selected
        actionBar.setSelectedNavigationItem(position);
      }

      @Override
      public void onPageScrolled(int arg0, float arg1, int arg2) {
      }

      @Override
      public void onPageScrollStateChanged(int arg0) {
      }
    });
  }

  @Override
  public void onTabReselected(Tab tab, FragmentTransaction ft) {
  }

  @Override
  public void onTabSelected(Tab tab, FragmentTransaction ft) {
    // on tab selected
    // show respected fragment view
    viewPager.setCurrentItem(tab.getPosition());
  }

  @Override
  public void onTabUnselected(Tab tab, FragmentTransaction ft) {
  }

}




Java Source Code List

com.besaba.srmu.AlertDialogManager.java
com.besaba.srmu.ConnectionDetector.java
com.besaba.srmu.CustomizedListView.java
com.besaba.srmu.FileCache.java
com.besaba.srmu.GamesFragment.java
com.besaba.srmu.ImageLoader.java
com.besaba.srmu.JSONParser.java
com.besaba.srmu.LazyAdapter.java
com.besaba.srmu.MainActivity.java
com.besaba.srmu.MemoryCache.java
com.besaba.srmu.MoviesFragment.java
com.besaba.srmu.PopUp.java
com.besaba.srmu.ServiceHandler.java
com.besaba.srmu.TopRatedFragment.java
com.besaba.srmu.Utils.java
com.besaba.srmu.XMLParser.java
com.besaba.srmu.adapter.TabsPagerAdapter.java
com.besaba.srmu.videoView.java