Using ArrayAdapter

 

The easiest adapter to use is – all you need to do is wrap one of these around a Java array or instance, and you have a fully‑functioning adapter:

 

 

New this

 

The constructor takes three parameters:

• The to use (typically this will be your activity instance)

• The resource ID of a view to use (such as a built‑in system resource ID, as previously shown)

• The actual array or list of items to show

By default, the will invoke on the objects in the list and wrap each of those strings in the view designated by the supplied resource. simply turns those strings into objects. Those widgets, in turn, will be shown the list or spinner or whatever widget uses this .

You can subclass and override to “roll your own” views:

Public getView

 

If null

New TextView this

 

SetText buildStringFor

 

Return

 

Here, receives three parameters:

• The index of the item in the array to show in the view

• An existing view to update with the data for this position (if one already existed, such as from scrolling – if null, you need to instantiate your own)

• The widget that will contain this view, if needed for instantiating the view

In the previous example, the adapter still returns a , but uses a different behavior for determining the string that goes in the view. Chapter 9 will cover fancier .

 








Дата добавления: 2015-05-16; просмотров: 896;


Поиск по сайту:

При помощи поиска вы сможете найти нужную вам информацию.

Поделитесь с друзьями:

Если вам перенёс пользу информационный материал, или помог в учебе – поделитесь этим сайтом с друзьями и знакомыми.
helpiks.org - Хелпикс.Орг - 2014-2024 год. Материал сайта представляется для ознакомительного и учебного использования. | Поддержка
Генерация страницы за: 0.003 сек.