When getView() in ArrayAdapter is called
Asked Answered
F

3

17

When creating a customized adapter for ListView in android, I see that I have to create a class the extends ArrayAdapter class and implements the getView(..) method.

All of that is OK, but I want to know the sequence of calling methods and executing. i.e. in which point of code the getView() is being called ?

Frisian answered 15/4, 2012 at 8:8 Comment(1)
Refer this LINK it has the clear and net explanation of CustomAdapter woth sample codeIncarnadine
S
9

From android docs - An Adapter object acts as a bridge between an AdapterView (such as ListView in your case) and the underlying data for that view. The Adapter provides access to the data items and is also responsible for making a View for each item in the data set.

So, whenever the ListView needs to display a particular row of data, it requests the associated adapter to provide the view corresponding to that the data at that position through getView() method. This may occur whenever the view needs to be updated on screen (eg. during creation/scroll etc.).

As an app developer, you need not worry about exactly at which point getView() is being called as long as you provide a concrete getView() implementation in your adapter. Make sure the method is efficient (thumbnails etc should be loaded in a background thread) for optimum performance.

Sulphurbottom answered 15/4, 2012 at 8:29 Comment(1)
How can you have the audacity to tell the asker that he doesn't need to worry about understanding how what he's using works?Blim
C
13

getView() of ArrayAdapter is called multiple times....

  1. as an when the new row is added...
  2. you scroll up and scroll down the list view....
  3. when the list is notfiedchanged..

Refer this link Android custom ArrayAdapter getView method called multiple times - resetting dynamic TextView value

Comprehensible answered 15/4, 2012 at 8:27 Comment(0)
S
9

From android docs - An Adapter object acts as a bridge between an AdapterView (such as ListView in your case) and the underlying data for that view. The Adapter provides access to the data items and is also responsible for making a View for each item in the data set.

So, whenever the ListView needs to display a particular row of data, it requests the associated adapter to provide the view corresponding to that the data at that position through getView() method. This may occur whenever the view needs to be updated on screen (eg. during creation/scroll etc.).

As an app developer, you need not worry about exactly at which point getView() is being called as long as you provide a concrete getView() implementation in your adapter. Make sure the method is efficient (thumbnails etc should be loaded in a background thread) for optimum performance.

Sulphurbottom answered 15/4, 2012 at 8:29 Comment(1)
How can you have the audacity to tell the asker that he doesn't need to worry about understanding how what he's using works?Blim
H
0
getView(int position, View view, ViewGroup parent) 

is called for the

List of Objects

of the nos of elements using

getItem(int position)

for the length of our List

so, it is called nos of times untill your entire list has been allocated a layout and data from list.

Himeji answered 15/4, 2012 at 8:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.