Reputation: 5440
Can anyone provide best working example to use supportmapfragment inside viewpager? I have tried many tutorials but I am not able to implement it. I just need the fragment, and its layout. I know how to setup viewpager. Thanks in advance.
Upvotes: 0
Views: 1246
Reputation: 2877
I was searching for some help on supportmapfrgment over stackoverflow, where upon i landed here.
I am currently working on a project like that.
Please feel free to contact me if you still need it now.
Upvotes: -1
Reputation: 2348
mViewPager = new CustomViewPager(this);
mViewPager.setId(R.id.viewPager);
setContentView(mViewPager);
final FragmentManager fm = getSupportFragmentManager();
mViewPager.setAdapter(new FragmentStatePagerAdapter(fm) {
@Override
public int getCount() {
return mContactList.size();
}
@Override
public Fragment getItem(int pos) {
Contact mContact = mContactList.get(pos);
int mCurrentPosition = mContact.getPosition();
return ContactDetailsFragment.newInstance(mCurrentPosition);
}
});
//loads the proper fragment on its meant-to-be position into the ViewPager
mViewPager.setCurrentItem(position);
public static ContactDetailsFragment newInstance(int position) {
Bundle args = new Bundle();
args.putInt(EXTRA_CONTACT_ID, position);
Log.i("ContactDetailsFragment","EXTRA_CONTACT_ID = "+EXTRA_CONTACT_ID);
ContactDetailsFragment mCdf = new ContactDetailsFragment();
mCdf.setArguments(args);
return mCdf;
}
Upvotes: 0
Reputation: 1007349
"Nothing seems to work" is a useless description of your symptoms. In the future, please feel free to actually explain what is going wrong.
That being said, here is a sample project showing the use of SupportMapFragment
in a ViewPager
. Note that you need to use a subclass of ViewPager
, overriding canScroll()
to ensure that the maps can still be swiped horizontally.
public class MapAwarePager extends ViewPager {
public MapAwarePager(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected boolean canScroll(View v, boolean checkV, int dx, int x,
int y) {
if (v instanceof SurfaceView || v instanceof PagerTabStrip) {
return(true);
}
return(super.canScroll(v, checkV, dx, x, y));
}
}
Upvotes: 2