CursorAdapter

在CursorAdapter里面,cursor记录的位置有系统管理,使用的时候将它当作只含有一个记录的对象。用户只需要直接用。

 

如果自己写一个类继承CursorAdapter,一般都要有private LayoutInflater layoutInflater;这个私有成员,而且这个私有成员在构造函数的时候要获得值。此外需要重写void setView(View view, Cursor cursor)、void bindView(View view, Context context, Cursor cursor)、View newView(Context context, Cursor cursor, ViewGroup parent),构造函数也要写出来,例子:

 

 

 

 

 

 

 

SimpleCursorAdapter类构造函数:

public SimpleCursorAdapter (Context context, int layout, Cursor c, String[] from, int[] to) 

Parameters

context  The context where the ListView associated with this SimpleListItemFactory is running 

layout  resource identifier of a layout file that defines the views for this list item. The layout file should include at least those named views defined in "to" 

c  The database cursor. Can be null if the cursor is not available yet. 

from  A list of column names representing the data to bind to the UI. Can be null if the cursor is not available yet. 

to  The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. Can be null if the cursor is not available yet.  

 

SimpleAdapter

public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) 

Parameters

context  The context where the View associated with this SimpleAdapter is running 

data  A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from" 

resource  Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to" 

from  A list of column names that will be added to the Map associated with each item. 

to  The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter.  

 

每次改变都应用各自的Adapter对象调用notifyDataSetChanged()来通知该对象已经变化,重新刷新列表。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值