閱讀412 返回首頁    go 阿裏雲 go 技術社區[雲棲]


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。


最後更新:2017-04-03 22:15:45

  上一篇:go Eclipse的JSP頁麵提示Multiple annotations found at this line或者String cannot be resolved to a type
  下一篇:go AWS“山寨”夥伴創意與產品,自我完善or殺雞取卵