0

I have a GridView using CustomAdapter, and I have an array list (size=20).

When I call adapter.notifyDataSetChanged(); - getView() is being called more times than it should (I understand that there is nothing to do about that). But I have a variable done==false on CustomAdapter class, and I want to change it to true once getView() is done working (after 20 times or even 50 times) , How can I control what comes once getView() is done? I want to change this variable to true. Where should I place done=true?

*The last getView()call is not necessary position==19

SHAI
  • 789
  • 3
  • 10
  • 43
  • Adnroid Documentation says: When the View is inflated, the parent View (GridView, ListView...) will apply default layout parameters unless you use inflate(int, android.view.ViewGroup, boolean) to specify a root view and to prevent attachment to the root. – Sneh Pandya Feb 13 '17 at 19:09
  • It also likely that requestLayout is being called repeatedly on your GridView as it fills in your grid, check for an optimizations you can do on your layout views to avoid these extra measuring and layout passes. – petey Feb 13 '17 at 19:55
  • why do you need this `done` flag? – petey Feb 13 '17 at 19:56

1 Answers1

0

You will not be able to do that! As Listview refreshes it's childs on scrolling

There is absolutely no guarantee on the order in which getView() will be called nor how many times.

source

Community
  • 1
  • 1
Atef Hares
  • 4,715
  • 3
  • 29
  • 61
  • But it's not what I asked- I already know that there is no guarantee on the order, I already know that there is no guarantee on the number of calls. But- at the end this method is done right? it's still Java. So what happens once it's done. – SHAI Feb 13 '17 at 18:58
  • I don't understands what you trying to do, if you put `done == true;` at end of the method it will be true at this call of the method and if done is an field in the adapter then it will remain true. – Atef Hares Feb 13 '17 at 19:04
  • I'll change it to false later it's not the issue. I need to change it to true only once the last call of "getView()" is called (after ** numbers of times) – SHAI Feb 13 '17 at 19:08
  • you can never detect last call of the method!!, you can only detect bottom of listview [user has scrolled to last row] or top of listview – Atef Hares Feb 13 '17 at 19:10
  • I have no scrolling on my app – SHAI Feb 13 '17 at 19:32
  • same exact issue here – Alejandro Monsalve Krause Jul 30 '22 at 16:00