I think you can write a custom adapter extending the BaseAdapter class and use it for both cases.
In your class that extends the BaseAdapter, you will have a List<DataEntry> , where a DataEntry is a Java POJO class representing data coming from the Internet or db (assuming it has the same properties). Assuming you populate List<DataEntry> objects with DataEntry objects that already contain data, you can do the following:
1) In the getView () method of the class that extends the BaseAdapter, in the inflat you will use the xml layout, which basically represents 1 row of data. Assuming that you will display data through a TextView, in 1 data row layout there will be as many TextView text elements as the number of data fields of your DataEntry. After bloating, you add values to TextViews, for example:
TextView someTextViewToDisplayField = (TextView) convertView.findViewById(R.id.yourID); someTextViewToDisplayField.setText(String.valueOf(dataEntry.getWhateverProperty()));
2) in the process of updating the user interface in the layout, you should have a ListView, for example:
<ListView android:id="@+id/YourListViewID" android:layout_width="fill_parent" android:layout_height="wrap_content"></ListView>
after which you initialize your class that extends BaseAdapter
ListView listView = (ListView) findViewById(R.id.YourListViewID); YourClassExtendingBaseAdapter adapter = new YourClassExtendingBaseAdapter(this, listOfEntryDataObjects); listView.setAdapter(adapter);
listOfEntryDataObjects List<DataEntry> already populated with data. 'this' in the constructor is the context associated with the current Activity, you are calling.
Class structure extending 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; }