1

I got a PagerView, inside the pager there are ListViews.

At each instantiateItem(ViewGroup collection, int position) func in ViewPager's PagerAdapter, i call an AsyncTask to populate the ListView in the current PagerItem.

So i got a horizontal scrollable area with ListViews, with different items in each ListView.

At the AsyncTask's onPostExecute() func, a set an Adapter which is configures the items in my ListViews.

Important part: I set 3 different OnClickListener to my ViewHoler's Views inside the Adapter.

So the mechanism and the issue are:

User scrolls the screen, switching between PagerItems. When scrolling to a new page, the relevant AsyncTask triggers, populating the currentListView, and calling an an Adapter to set it to the listView, configuring its Views.

Issue is simple yet so confusing to me:

When i firstly scroll to a page, all the OnClickListeners i set inside the Adapter are working very fine. All the items in the ListView are responsive and works well.

Issue: After this, i scroll 2-3 pages away from this page, THEN scrolls back to the page i was testing the OnClick methods. And here comes the error:

The OnClickListeners are not working from this point, they are like i didnt set them, my views in the listViews are just not responsible from this point.

It looks like the Adapter somehow "forgets" the OnClickListeners, or something else like that.

Pls if you have any tips, feel free to advice me. I show code if you want just tell me which part because this issue is related to so many Classes.

Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
  • add log to `instantiateItem(ViewGroup collection, int position)` and you'll get it ... if you back to the first view after you move more pages than getOffscreenPageLimit the first view is not the same as were creatad at first time – Selvin Jul 03 '13 at 10:56
  • I think is because the listeners are set on the other views. When u swipe 2 items and u r on the third view, there is where your listeners get lost. Is it right? When u swipe to the 3rd item is when ondestroyview gets called for the first item of the viewpager. If u provide dome code for the adapter... – jpardogo Jul 03 '13 at 10:57
  • @Selvin if you add this as an answer i will accept it ;) Problem Solved. – Adam Varhegyi Jul 03 '13 at 11:08

0 Answers0