Android viewpager dynamic loading problem

When I was working on the project today, I struggled for a long time. I added the view dynamically. At the beginning, it was handled according to other adapters, but it would not refresh the view, turn back and forth a few pages, and the view would be overwritten. Finally, I manually called the destroyitem and instantiateitem methods of the adapter, but it still couldn't. finally, I rewritten removeallviews and instantiateitem in notifydatasetchanged. It was a little effective, but it was still not ideal. Finally, the pageradapter method should be rewritten when querying data

As follows:

When refreshing the data, first remove allviews, then reset the data, and finally notify datasetchanged.

However, when the data is reloaded, the destroitem will be called after notifydatasetchanged, which will cause problems. The index of the views recorded by the destroitem is greater than 0, but when the count of the reloaded views is 1, an array out of bounds error will occur when the removeview is removed. The processing method is

It's done. I'm very depressed. The third-party control is not perfect. It's not as good as other adapters. Record this depressing trip through this article, ha ha.

The above is the dynamic loading problem of Android viewpager introduced by Xiaobian. I hope it will be helpful to you. If you have any questions, please leave me a message, and Xiaobian will reply to you in time. Thank you very much for your support for the programming tips website!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>