When I was working on the project today, I was struggling with it for a long time. I dynamically added the view. At the beginning, I followed other adapters to process it, but I would not refresh the view. I turned around for a few pages, and I would also overwrite the view. Finally, I manually called the destroyItem and instantiateItem methods of the adapter, but it still didn't work. Finally, I rewrite the removeAllViews and instantiateItem in notifyDataSetChanged, which was a bit effective, but it was still not ideal. Finally, the method of rewriting the PagerAdapter in querying information
as follows:
public int getItemPosition(Object object) { return POSITION_NONE; }
, then removeAllViews when refreshing the data first, then reset the data, and finally notifyDataSetChanged, and that's it.
However, when notifyDataSetChanged is reloaded, destroyItem will be called. At this time, there will be a problem. The index of the view recorded by destroyItem is greater than 0, but when the count of the reloaded view is 1, this is when the array out-of-bounds error occurs when the removeView is removed. The method is to deal with it.
@Override public void destroyItem(View arg0, int arg1, Object arg2) { if (getCount() > 1) { ((GridViewPager) arg0).removeView(((GridViewPager) arg0) .getViewList().get(arg1)); } }
After finishing it, I was very depressed. It was the third party's control. It was not perfect yet, so I don't think that other Adapters are as good as it is. Record this depressed journey through this article, haha.
The above is the Android ViewPager dynamic loading problem introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!