/** * The {@link android.support.v4.view.PagerAdapter} that will provide * fragments for each of the sections. We use a * {@link FragmentPagerAdapter} derivative, which will keep every * loaded fragment in memory. If this becomes too memory intensive, it * may be best to switch to a * {@link android.support.v4.app.FragmentStatePagerAdapter}. */ private SectionsPagerAdapter mSectionsPagerAdapter;
/** * The {@link ViewPager} that will host the section contents. */ private ViewPager mViewPager;
// final Button like=(Button)findViewById(R.id.like);
// like.setOnClickListener(
// new View.OnClickListener()
//{
// public void onClick(View v)
// {
// like.setBackground(getResources().getDrawable(R.drawable.dog));
// }
// });
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());
// Set up the ViewPager with the sections adapter.
mViewPager = (ViewPager) findViewById(R.id.container);
mViewPager.setAdapter(mSectionsPagerAdapter);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_ighome, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/** * A {@link FragmentPagerAdapter} that returns a fragment corresponding to * one of the sections/tabs/pages. */ public class SectionsPagerAdapter extends FragmentPagerAdapter {
public SectionsPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position){
case 0:
tab1 t1 = new tab1();
return t1;
case 1:
tab2 t2 =new tab2();
return t2;
case 2:
tab3 t3=new tab3();
return t3;
case 3:
tab4 t4=new tab4();
return t4;
case 4:
tab5 t5=new tab5();
return t5;
default:
return null;
}
}
@Override
public int getCount() {
// Show 5 total pages.
return 5;
}
}
}