cursorAdapter简介

public class MySimpleCursorAdapter extends SimpleCursorAdapter {
	private Cursor m_cursor;
	private Context m_context;

	@Override
	public View newView(Context context, Cursor cursor, ViewGroup parent) {
		final View view = super.newView(context, cursor, parent);
		ViewHolder holder = new ViewHolder();
		holder.titleView = (TextView) view.findViewById(R.id.title);
		holder.linkView = (TextView) view.findViewById(R.id.Link);
		holder.descriptionView = (TextView) view.findViewById(R.id.Description);
		holder.categoryView = (TextView) view.findViewById(R.id.Category);
		holder.authorView = (TextView) view.findViewById(R.id.Author);
		holder.pubDateView = (TextView) view.findViewById(R.id.PubDate);

		view.setTag(holder);
		return view;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		return super.getView(position, convertView, parent);
	}

	public MSimpleCursorAdapter(Context context, int layout, Cursor c,
			String[] from, int[] to) {
		super(context, layout, c, from, to);
		m_cursor = c;
		m_context = context;
	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {
		ViewHolder holder = (ViewHolder) view.getTag();
		setViewText(holder.titleView, cursor.getString(cursor
				.getColumnIndex(Items.TITLE)));
		setViewText(holder.linkView, cursor.getString(cursor
				.getColumnIndex(Items.LINK)));
		setViewText(holder.descriptionView, cursor.getString(cursor
				.getColumnIndex(Items.DESCRIPTION)));
		setViewText(holder.categoryView, cursor.getString(cursor
				.getColumnIndex(Items.CATEGORY)));
		setViewText(holder.authorView, cursor.getString(cursor
				.getColumnIndex(Items.AUTHOR)));
		setViewText(holder.pubDateView, cursor.getString(cursor
				.getColumnIndex(Items.PUBDATE)));
		super.bindView(view, context, cursor);
	}

	final static class ViewHolder {
		public TextView titleView;
		public TextView linkView;
		public TextView descriptionView;
		public TextView categoryView;
		public TextView authorView;
		public TextView pubDateView;
	}
}

 bindView 赋值

newView 初始化

public void changeCursor (Cursor cursor)

更改底层的游标为新传入的游标。如果游标已经存在则先关闭这个已存在的游标。

  参数

  cursor Cursor

猜你喜欢

转载自h529820165.iteye.com/blog/1609407