ラベル getView の投稿を表示しています。 すべての投稿を表示
ラベル getView の投稿を表示しています。 すべての投稿を表示

2013年9月18日水曜日

AdapterのgetView()

ListViewに内容を表示させるには、AdapterはデータとListViewの中間役になります。Adapterの役割の中心は、getView()です。ListViewは新しいrowを表示する際、その都度getView()を呼び出します。

public abstract View getView (int positionView convertView, ViewGroup parent)

Added in API level 1
Get a View that displays the data at the specified position in the data set. You can either create a View manually or inflate it from an XML layout file. When the View is inflated, the parent View (GridView, ListView...) will apply default layout parameters unless you use inflate(int, android.view.ViewGroup, boolean) to specify a root view and to prevent attachment to the root.
Parameters
positionThe position of the item within the adapter's data set of the item whose view we want.
convertViewThe old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view. Heterogeneous lists can specify their number of view types, so that this View is always of the right type (see getViewTypeCount() and getItemViewType(int)).
parentThe parent that this view will eventually be attached to
Returns
  • A View corresponding to the data at the specified position.