9 月
10
2009

Compare Android ArrayAdapter with Flex ArrayCollection

因為習慣了Flex的思考方式,所以感覺世界大一同阿!只是class名字換了XD

API解說

A ListAdapter that manages a ListView backed by an array of arbitrary objects. By default this class expects that the provided resource id references a single TextView. If you want to use a more complex layout, use the constructors that also takes a field id. That field id should reference a TextView in the larger layout resource. However the TextView is referenced, it will be filled with the toString() of each object in the array. You can add lists or arrays of custom objects. Override the toString() method of your objects to determine what text will be displayed for the item in the list. To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup) to return the type of view you want.

在使用UI物件的dataprovider(通常是ArrayCollection)時,Flex可以指定UI物件顯示該value object的特定一個attribute,或者組合成一個ItemRenderer來輸出畫面

Android中他同樣使用類似Flex的dataprovider的概念,叫做ArrayAdapter,不同的是,在輸出顯示畫面時,是呼叫ArrayAdapter中元素的toString()方法,也就是我們如果要在ArrayAdapter放入非String的複雜value object,並且要整理輸出在畫面上,就得要override該class的toString()方法

同Flex的ItemRenderer,override getView(int, View, ViewGroup) 方法來輸出其他view

 

做個總結

Flex ==> Android

ArrayCollection ==> ArrayAdapter

dataField ==> override toString()

ItemRenderer ==> override getView()

Written by in: 電腦三兩事 | 標籤: ,

2 Comments »

RSS feed for comments on this post. TrackBack URL


Leave a Reply

Powered by WordPress | Theme: Aeros 2.0 by TheBuckmaker.com