When is the getView() method of ListView called?
I'm working on ListView
. I want to know when ex开发者_StackOverflow社区actly getView()
is called. Is it called once the adapter is set? And does the line next to "setting adapter" get called once the getView()
method completes execution?
Please help me know which line gets executed once the getView()
finishes execution.
That would be a great help for me.
Thanks in advance, Vaishnvai
getView()
is called for each item in the list you pass to your adapter.
It is called when you set adapter. When getView()
is finished the next line after setAdapter(myAdapter)
is called.
In order to debug getView()
you must toggle a breakpoint on it because you can't step into getView()
from setAdapter(myAdapter)
.
getView()
is also called after notifyDataSetChanged()
and on scrolling.
To be more clear, getView() is called whenever a new item is displayed on screen, at the count of displayed items. Which means, if you have 1 million items but 15 of them fits on screen, getView is called 15 times. Whenever you scroll up/down and new items appear, getView() is called for new ones. And you should be aware of recycler mechanism, too. Which holds a template item layout for each item type, and sends in this view to getView() method as convertView parameter, so you could use it in order to prevent layout inflation.
精彩评论