MainActivity(extends fragmentActivity) has listview which calls listviewadapter within which have a ViewPager with ViewpagerAdapter now if i need to generate 5 fragments within ViewPager how to pass getFragmentManager() to adapter.
MainActivity [fragmentActivity] ----> Listview ----> ListviewAdapter[Custom BaseAdapterAdapter with getview of layout ViewPager] ---> ViewPager ---> ViewPageAdapter[i need to create 5 fragments based on position?]
It will be too long if i paste the whole code so i have attached only
public class ViewPagerAdapter extends PagerAdapter {
ArrayList<ModelClass> arrayModelClasses = new ArrayList<ModelClass>();
Context mcontext ;
LinearLayout layouttest;
final int PAGE_COUNT = 5;
private String titles[] = new String[] { "Villa ","", "" ,"","",""};
private int[] imageResId = { R.drawable.transparant,R.drawable.ic_action_place, R.drawable.icon_3d1,
R.drawable.icon_flooplan,R.drawable.icon_gallery,R.drawable.icon_location };
@SuppressLint("NewApi")
@Override
public void finishUpdate(ViewGroup container) {
// TODO Auto-generated method stub
super.finishUpdate(container);
}
public ViewPagerAdapter(ArrayList<ModelClass> arrayModelClasses , Context context) {
super();
this.arrayModelClasses = arrayModelClasses;
this.mcontext= context;
}
@Override
public boolean isViewFromObject(View collection, Object object) {
return collection == ((View) object);
}
View view;
@Override
public Object instantiateItem(View collection, int position) {
if (position == 0) {
//need to call fragment 1
}if (position == 1) {
//need to call fragment 2
}if (position == 2) {
//need to call fragment 3
}if (position == 3) {
//need to call fragment 4
}if (position == 4) {
//need to call fragment 5
}
return view;
}
@Override
public void destroyItem(View container, int position, Object object) {
((ViewPager) container).removeView((View) object);
}
@Override
public CharSequence getPageTitle(int position) {
Drawable image = mcontext.getResources().getDrawable(imageResId[position]);
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
SpannableString sb = new SpannableString(" " + titles[position] );
ImageSpan imageSpan = new ImageSpan(image, ImageSpan.ALIGN_BOTTOM);
sb.setSpan(imageSpan, 0, 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return sb;
}
@Override
public int getCount() {
return PAGE_COUNT;
}
}
link but it uses FragmentPagerAdapter for viewPager and passed the getSupportFragmentManager from FragmentActivity but its not possible with 2 adapters so help.
Question: How to create fragment within viewPager which is inside listview. sorry if its confusing.
Thanks,