Public class extends. SetListAdapter new CheckAdapter this

 

Public onCreate

Super onCreate

SetContentView

 

New

 

For

Add new RowModel

 

 

SetListAdapter new CheckAdapter this

FindViewById

 

 

Private getModel

Return getListAdapter getItem

 

 

Public onListItemClick

 

SetText getModel toString

 

 

Class extends

 

 

CheckAdapter

Super

 

This

 

 

Public getView

 

If null

GetLayoutInflater

Inflate null

New ViewWrapper

SetTag

GetRatingBar

 

 

New OnRatingBarChangeListener

Public onRatingChanged

 

GetTag

GetModel

 

GetParent

FindViewById

SetText toString

 

SetOnRatingBarChangeListener

Else

GetTag

GetRatingBar

 

 

GetModel

 

GetLabel setText toString

SetTag new Integer

SetRating

 

Return

 

Class

 

RowModel

This

 

 

Public toString

If

Return toUpperCase

 

 

Return

 

Here is what is different between our earlier code and this activity and implementation:

• While we are still using items as the list of nonsense words, but rather than pouring that array straight into an , we turn it into a list of objects. is this demo’s poor excuse for a mutable model; it holds the nonsense word plus the current checked state. In a real system, these might be objects populated from a , and the properties would have more business meaning.

• Utility methods like had to be updated to reflect the change from a pure String to use a .

• The subclass () in looks to see if is null. If so, we create a new row by inflating a simple layout (see the following code) and also attach a (also in the following code). For the row’s , we add an anonymous listener that looks at the row’s tag () and converts that into an , representing the position within the that this row is displaying. Using that, the checkbox can get the actual for the row and update the model based upon the new state of the rating bar. It also updates the text adjacent to the when checked to match the rating‑bar state.

• We always make sure that the has the proper contents and has a tag (via ) pointing to the position in the adapter the row is displaying.

The row layout is very simple: just a and a inside a :

 

 

The is similarly simple, just extracting the and the out of the row :

Class

 

Null

Null

 








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


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

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

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

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