Android适配器之CursorAdapter

来源:互联网 发布:java对接微信公众平台 编辑:程序博客网 时间:2024/04/30 15:52

CursorAdapter

public abstract class

CursorAdapter

extends BaseAdapter
implements Filterable
java.lang.Object   ↳android.widget.BaseAdapter    ↳android.widget.CursorAdapter

Public Methodsabstract voidbindView(View view, Context context, Cursor cursor)

Bind an existing view to the data pointed to by cursor
voidchangeCursor(Cursor cursor)
Change the underlying cursor to a new cursor.
CharSequenceconvertToString(Cursor cursor)

Converts the cursor into a CharSequence.

intgetCount()CursorgetCursor()
Returns the cursor.
ViewgetDropDownView(int position, View convertView, ViewGroup parent)

Get a View that displays in the drop down popup the data at the specified position in the data set.

FiltergetFilter()

Returns a filter that can be used to constrain data with a filtering pattern.

FilterQueryProvidergetFilterQueryProvider()
Returns the query filter provider used for filtering.
ObjectgetItem(int position)longgetItemId(int position)ViewgetView(int position, View convertView, ViewGroup parent)booleanhasStableIds()
Indicates whether the item ids are stable across changes to the underlying data.
ViewnewDropDownView(Context context, Cursor cursor, ViewGroup parent)
Makes a new drop down view to hold the data pointed to by cursor.
abstract ViewnewView(Context context, Cursor cursor, ViewGroup parent)
Makes a new view to hold the data pointed to by cursor.
CursorrunQueryOnBackgroundThread(CharSequence constraint)
Runs a query with the specified constraint.
voidsetFilterQueryProvider(FilterQueryProvider filterQueryProvider)
Sets the query filter provider used to filter the current Cursor.
CursorswapCursor(Cursor newCursor)
Swap in a new Cursor, returning the old Cursor.
Protected Methodsvoidinit(Context context, Cursor c, boolean autoRequery)
This method was deprecated in API level 11. Don't use this, use the normal constructor. This will be removed in the future.
voidonContentChanged()
Called when the ContentObserver on the cursor receives a change notification.
这是API上给出的..可以看出 继承与 BaseAdapter

实际开发中一般也是会自定义cursor适配器;下面看代码:


必须实现以下函数
abstract View        newView(Context  context, Cursor  cursor, ViewGroup  parent)
    Makes a new view to hold the data pointed to by cursor.
abstract void        bindView(View  view, Context  context, Cursor  cursor)
    Bind an existing view to the data pointed to by cursor

newView该函数第一次回调用后,如果数据增加后也会再调用,但是重绘是不会调用的。
数据增加后,回调用该函数来生成与新增数据相对应的view。
bindView函数第一次回调用后,如果数据更新也会再调用,但重绘会再次调用的。


数据更新:

adapter.changeCursor(cursor);

adapter.notifyDataSetChanged()



public class MyCurasorAdapter extends CursorAdapter {
private LayoutInflater layoutInflater;
private Context mContext;
public MyCurasorAdapter(Context context, Cursor c, int flags) {
super(context, c, flags);
this.mContext = context;
}
@Override
public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
View view = LayoutInflater.from(mContext).inflate(
R.layout.listview_item, null);
return view;
}
@Override
public void bindView(View convertView, Context arg1, Cursor arg2) {
// TextView title = (TextView) convertView.findViewById(R.id.title);
TextView soure = (TextView) convertView.findViewById(R.id.source);
TextView title = (TextView) convertView.findViewById(R.id.title);
TextView source = (TextView) convertView.findViewById(R.id.source);
TextView create_time = (TextView) convertView
.findViewById(R.id.create_time);
TextView nickname = (TextView) convertView.findViewById(R.id.nickname);
ImageView imageView = (ImageView) convertView
.findViewById(R.id.wap_thumb);
source.setText(" ");
title.setText(arg2.getString(arg2.getColumnIndex("title")));
create_time.setText(arg2.getString(arg2.getColumnIndex("create_time")));
nickname.setText(arg2.getString(arg2.getColumnIndex("nickname")));
if (arg2.getString(arg2.getColumnIndex("wap_thumb")).equals("")) {
} else {
ImageJudge imageJudge = new ImageJudge(imageView,
arg2.getString(arg2.getColumnIndex("wap_thumb")));
imageJudge.ImgaeDown();
}
}
}


0 0
原创粉丝点击