ITEEDU

CursorAdapter抽象类

CursorAdapter
extends BaseAdapter
implements Filterable

主要实现如下两个方法。

public View newView(Context context, Cursor cursor, ViewGroup parent)
public void bindView(View view, Context context, Cursor cursor)

newView会创建一个item的view,然后bindView再给这个view中的项设置数据。

基本结构

	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		View view = mInflater.inflate(R.layout.tweet, parent, false);
		TweetCursorAdapter.ViewHolder holder = new ViewHolder();
		holder.tweetUserText = (TextView) view
				.findViewById(R.id.tweet_user_text);
		...//设置holder的值
		view.setTag(holder);
		return view;
	}

	private static class ViewHolder {
		public TextView tweetUserText;
	...
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		TweetCursorAdapter.ViewHolder holder = 
	(TweetCursorAdapter.ViewHolder) view.getTag();
	holder.tweetUserText.setText(cursor.getString(mUserTextColumn));
	...//设置view中对应项的内容
	}