Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is the getView() method of ListView called?

I'm working on ListView. I want to know when exactly 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

like image 423
Vaishnavi Avatar asked Aug 17 '11 06:08

Vaishnavi


People also ask

What is getView method in Android?

getView(int position, View convertView, ViewGroup parent) Get a View that displays the data at the specified position in the data set. abstract int. getViewTypeCount() Returns the number of types of Views that will be created by getView(int, View, ViewGroup) .

What is convertView?

convertView is the ListView Item Cache that is not visible, and hence it can be reused. It lets the ListView need not create a lot of ListItems, hence saving memeory and making the ListView more smooth.


1 Answers

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.

like image 157
superM Avatar answered Sep 20 '22 23:09

superM