In my application, I am trying to implement a map view inside a ViewPager. I have 4 different pages in the application. and MapView is on page 4. I successfully loaded the map, but when I return to the first page, the fourth view must be destroyed using the destroyItem () method. And if I scroll to the 4th page, it crashes from the third page shows an error in logcat:
05-10 13:14:50.152: E/AndroidRuntime(620): java.lang.IllegalStateException: You are only allowed to have a single MapView in a MapActivity
I know that MapActivity has only one mapping. But I can’t solve it - can someone help me?
Code below:
public Object instantiateItem(View collection, int position) {
LayoutInflater inflater = (LayoutInflater) collection.getContext()
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
context = collection.getContext();
int resId = 0;
int flag = resId;
switch (position) {
case 0:
resId = R.layout.farleft;
view = inflater.inflate(resId, null);
break;
case 1:
resId = R.layout.left;
view = inflater.inflate(resId, null);
break;
case 2:
resId = R.layout.right;
view = inflater.inflate(resId, null);
break;
case 3:
resId = R.layout.mylocator;
view = inflater.inflate(resId, null);
break;
}
((ViewPager) collection).addView(view, 0);
return view;
}
@Override
public void destroyItem(View arg0, int arg1, Object arg2) {
((ViewPager) arg0).removeView((View) arg2);
Log.d("destroyItem", "" + arg2);
}
source
share