Mapview Not Being Removed From Viewpager?
In my application I'm trying to implement a map view inside a ViewPager. I have 4 different pages in the application. and MapView is in the 4th page. I did successfully load the ma
Solution 1:
I have found the solution. Inside your fragment which contains the Map and that is used by the ViewPager, put that :
private View myView;
@Overridepublic View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (this.myView == null){
this.myView = inflater.inflate(R.layout.my_layout, container, false);
}
elseif (this.myView.getParent() != null) {
FrameLayout parentView = (FrameLayout) this.myView.getParent();
parentView.removeView(this.myView);
}
returnthis.myView;
}
It works fine for me, tell me if it works for you ;)
Solution 2:
One issue with the Android View Pager is that recycling views has to be done manually. In your case it is possible that the view has not been destroyed yet but is created a second time when the view is instantiated again. You could save your view for each page and then return it in instantiateItem if it hasn't been destroyed already.
Post a Comment for "Mapview Not Being Removed From Viewpager?"