A Dynamic Presentation

 

This technique – supplying an alternate layout to use for rows – handles simple cases very nicely. However, it isn’t sufficient when you have more‑complicated scenarios for your rows, such as the following:

• Not every row uses the same layout (e.g., some have one line of text, others have two).

• You need to configure the widgets in the rows (e.g., different icons for different cases).

In those cases, the better option is to create your own subclass of your desired , override , and construct your rows yourself. The method is responsible for returning a , representing the row for the supplied position in the adapter data.

For example, let’s rework the preceding code to use so we can have different icons for different rows – in this case, one icon for short words and one for long words (from the sample project at http://apress.com/):

Public class extends

 

Public onCreate

Super onCreate

SetContentView

SetListAdapter new IconicAdapter this

FindViewById

 

 

Public onListItemClick

 

SetText

 

 

Class extends

 

 

IconicAdapter

Super

 

This

 

 

Public getView

 

GetLayoutInflater

Inflate null

FindViewById

 

SetText

 

If length

FindViewById

 

SetImageResource

 

 

Return

 

The theory is that we override and return rows based on which object is being displayed, where the object is indicated by a position index into the . However, if you look at the implementation shown in the code here, you will see a reference to a class – and that concept takes a little bit of an explanation.

 








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


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

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

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

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