BaseAdapter&GridView

Adapter是连接后端数据和前端显示的适配器接口,是数据和UI(View)之间一个重要的纽带。在常见的View(ListView,GridView)等地方都需要用到Adapter。如下图直观的表达了Data、Adapter、View三者的关系:


BaseAdapter是一个abstrace class要使用时必须重写他的方法,注意这些方法都是抽象方法,分别生命在Adapter abstrace class中。分别是:

public int getCount()返回该Adapter中装载的资源的数量

public Object getItem(int position)从data set中取出指定poistion处的数据

public long getItemId(int position)return position处的item所在的row id

public View getView(int position, View convertView, ViewGroup parent)

position:data set 中position处的数据,this data we want to view.

convertView:使用之前用convertView ? null判断,if can't covert to a view来装载数据然后显示的话,就需要创建一个新的view了;了;来装载数据.

parent: as the convertView's parent view and must attached to parent.

after call this function will return the view with data in the position  of  the adapter. 

点击时候的响应函数:

public abstract void onItemClick (AdapterView<?> parent, View view, int position, long id)
parentThe AdapterView where the click happened.发生click事件的那个AdapterView
viewThe view within the AdapterView that was clicked (this will be a view provided by the adapter)
positionThe position of the view in the adapter.
idThe row id of the item that was clicked. 

ImageSwitcher:


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值