0

Adapter: here I want images

public class MyFragmentPagerAdapter extends FragmentPagerAdapter{
 
 final int PAGE_COUNT = 5;
 Context mContext;

 /** Constructor of the class */
 public MyFragmentPagerAdapter(FragmentManager fm) {
  super(fm);
 }

 /** This method will be invoked when a page is requested to create */
 @Override
 public Fragment getItem(int arg0) {
  
  MyFragment myFragment = new MyFragment();
  Bundle data = new Bundle();
  data.putInt("current_page", arg0+1);
  myFragment.setArguments(data);
  return myFragment;
 }

 /** Returns the number of pages */
 @Override
 public int getCount() {  
  return PAGE_COUNT;
 }
 
 @Override
 public CharSequence getPageTitle(int position) {  
  
  return "Page #" + ( position + 1 );
  
 }
 

 
 
}
Fragment

public class MyFragment extends Fragment{
 
 int mCurrentPage;
 
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  
  /** Getting the arguments to the Bundle object */
  Bundle data = getArguments();
  
  /** Getting integer data of the key current_page from the bundle */
  mCurrentPage = data.getInt("current_page", 0);
  
 }
 
 @Override
 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
  View v = inflater.inflate(R.layout.myfragment_layout, container,false);    
  TextView tv = (TextView ) v.findViewById(R.id.tv);
  tv.setText("You are viewing the page #" + mCurrentPage + "\n\n" + "Swipe Horizontally left / right"); 
  return v;  
 }
}
MainActivity

public class MainActivity extends FragmentActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        /** Getting a reference to the ViewPager defined the layout file */        
        ViewPager pager = (ViewPager) findViewById(R.id.pager);
        
        /** Getting fragment manager */
        FragmentManager fm = getSupportFragmentManager();
        
        /** Instantiating FragmentPagerAdapter */
        MyFragmentPagerAdapter pagerAdapter = new MyFragmentPagerAdapter(fm);
        
        /** Setting the pagerAdapter to the pager object */
        pager.setAdapter(pagerAdapter);
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}

I want to add custom images and text in the ViewPager just like in the image(circled part). I'm getting text using this link. But I want custom Image above text and custom string[] for text like here. image.

Somnath Pal
  • 1,570
  • 4
  • 23
  • 42
  • Possible duplicate of [Customize new TabLayout in support design library](http://stackoverflow.com/questions/30950999/customize-new-tablayout-in-support-design-library) – denvercoder9 Jan 11 '16 at 07:31
  • Check out [this](https://www.youtube.com/watch?v=WSaSNX5QI-E) tutorial by slidenerd. – denvercoder9 Jan 11 '16 at 07:33
  • I'm not using TabLayout as I'm using Eclipse. Can we still use the code as shown here(https://guides.codepath.com/android/Google-Play-Style-Tabs-using-TabLayout) ? @RafiduzzamanSonnet – Somnath Pal Jan 11 '16 at 07:43
  • 1
    Eclipse is the IDE and TabLayout is part of the android SDK. They have no relation with each other. Yes, you can use the code shown in the tutorial. But I'd suggest you to use Android Studio since eclipse is no longer supported. :) – denvercoder9 Jan 11 '16 at 07:50

0 Answers0