BaseAdapter クラスを拡張してカスタム アダプタを作成し、両方のケースで使用できると思います。
BaseAdapter を拡張するクラスにはList<DataEntry>、DataEntry が Java POJO クラスであり、web または db からのデータを表す があります (同じプロパティがあると仮定します)。に DataEntry オブジェクトを設定し、既にデータが含まれていると仮定するとList<DataEntry>、次のように実行できます。
1) BaseAdapter を拡張するクラスの getView() メソッドでは、インフレートで、基本的に 1 つのデータ行を表す xml レイアウトを使用します。TextView を介してデータを表示すると仮定すると、1 データ行レイアウトには、DataEntry オブジェクトのデータ フィールドの数と同じ数の TextView 要素が含まれます。インフレートした後、次のように TextViews に値を入れます。
TextView someTextViewToDisplayField = (TextView) convertView.findViewById(R.id.yourID);
someTextViewToDisplayField.setText(String.valueOf(dataEntry.getWhateverProperty()));
2) レイアウトの UI を更新するプロセスでは、次のような ListView が必要です。
<ListView android:id="@+id/YourListViewID" android:layout_width="fill_parent"
android:layout_height="wrap_content"></ListView>
その後、 BaseAdapter を拡張するクラスを初期化します
ListView listView = (ListView) findViewById(R.id.YourListViewID);
YourClassExtendingBaseAdapter adapter =
new YourClassExtendingBaseAdapter(this, listOfEntryDataObjects);
listView.setAdapter(adapter);
listOfEntryDataObjects にはList<DataEntry>すでにデータが入力されています。コンストラクターの「this」は、現在のアクティビティに関連付けられたコンテキストであり、呼び出しを行います。
BaseAdapter を拡張するクラスの構造:
public class YourClassExtendingBaseAdapter extends BaseAdapter {
private Context context;
private List<DataEntry> entries;
public YourClassExtendingBaseAdapter(Context context,
List<DataEntry> entries) {
this.context = context;
this.entries = entries;
}
// Overwriting necessary methods
}