android适配器的概念(未完待续)

下面这个类是一个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,其中数组适配器以数组的形式存放数据,





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值