How is the getView () adapter called getView ()?

I looked around a bit, but did not find a real answer to this question. I am just starting to learn about Android adapters and asked a few questions. First, do I need to call getView () manually or automatically get a call? If so, when is it really called? Finally, I noticed there is a parameter for the "position" in the list. Is it something that I have to increase with iteration, or is it somehow increasing?

thanks!

+5
source share
3 answers

First, do I need to call getView () manually or call it automatically?

No, it is automatically called.

If so, when is it really called?

It will be called when the user does something with your ListView , for example, when the ListView displays a new item when scrolling through it.

Finally, I noticed there is a parameter for the "position" in the list. Is this something I have to increase with iteration or does it somehow increase somehow?

No, this will be the position of your list item automatically. The same for other parameters, such as (default) View convertView , this will be the View current item ( ListView string).

+3
source

This is part of how the adapter works. You do not need to call any of these methods, since it is implicitly called through Listview.

Look at this,

http://www.vogella.com/tutorials/AndroidListView/article.html

This is a good article on how to use Listview.

0
source

An adapter is a kind of connection between AdapterView (ListView, GridView, etc.) and data arrays. The adapter generates flags that will be displayed in the AdapterView. Therefore, when the ListView needs to display elements, it first calls the adapter's getCount () method, after some measurements, it calls several getView () calls to fill the visible part of the list with the elements. And then, while scrolling, the ListView will call getView () from the adapter for the following items. It is important not to make any assumptions about the order of the getView () calls - it is not necessary that listview calls getView () in the same order as your data. Therefore, you don’t need to worry about increasing the position index - this argument is used for a situation, for example, when you need to display two different backgrounds for even and odd lines - and you can use the position to decide which color you need to use. There is a good presentation on the anatomy of ListView

0
source

Source: https://habr.com/ru/post/1207174/


All Articles