The ViewPager has 5 pages (which I want to reuse then), the corresponding PagerAdapter has an array with views, I fill it at the start of the program and then show the central page:
0 1 |2| 3 4 Now, when paging, I use the page from the opposite end of the array, updating it with new data (based on calendar dates), depending on the paging direction:
повторное использование: 4 0 |1| 2 3 или 1 2 |3| 4 0 и тд I onPageSelected pages in onPageSelected from ViewPager.OnPageChangeListener , but at the same time when scrolling in the animation there is a delay due to the rather slow code when updating the page (the code is not accelerated).
Therefore, I rendered the slow code into a separate thread and then updated the pages using the post view method. Work has become faster, but still slows down.
The question is how can you optimize / rewrite such an algorithm?
Update
The question is this. As I wrote, the execution of the code was carried out into the stream, but it still slows down due to the large number of views on the page, apparently due to the post call, I tried to do everything in the stream from beginning to end - from inflite to filling up the views, but the problem occurred trying to slip a page created like this in a PagerAdapter and then call notifyDataSetChanged() - after that crashes
android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views. Maybe this is due to the fact that I, as a rootView transfer the rootView created in the main thread?
getLayoutInflater().inflate(R.layout.layout_calendar, mViewPager, false); Update 2
It seems to have figured out with this, I will reply