Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When getView() in ArrayAdapter is called

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 ?

like image 598
Adham Avatar asked Apr 15 '12 08:04

Adham


People also ask

When getView is called in android?

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.

What is ArrayAdapter used for?

You can use this adapter to provide views for an AdapterView , Returns a view for each object in a collection of data objects you provide, and can be used with list-based user interface widgets such as ListView or Spinner .


2 Answers

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

like image 153
Kri Avatar answered Sep 16 '22 20:09

Kri


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.

like image 32
Anamoy Avatar answered Sep 19 '22 20:09

Anamoy