下面这个类是一个Activity,继承了ListActivity,他显示一系列的项,这些项里面存放的数据来源于适配器,这是自己写的 只是部分代码,后面有个简单例子
android API这样解释ListActivity
ListActivity hosts a ListView
object that can be bound to different data sources, typically either an array or a Cursor holding query results. Binding, screen layout, and row layout are discussed in the following sections.
public class ShowListView extends ListActivity{
private List<String> list = new ArrayList<String>();//定义一个列表,存放数据
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
list = MainActivity.getList();//list中的数据来源于 MainActivity 中的list
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, list);//数组适配器,第二个参数是表示简单的列表,只显示一列,list中是存放的数据
setListAdapter(adapter);将list个适配器绑定,以获取适配器中的数据
}
android中的常用适配器:simpleAdapter,ArrayAdapter,BaseAdapter,其中数组适配器以数组的形式存放数据,