欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Android重写SimpleCursorAdapter例子 博客分类: Android

程序员文章站 2024-03-02 11:56:22
...
public class MySimpleCursorAdapter extends SimpleCursorAdapter {
	private LayoutInflater mInflater;
	private OnMyAdaptertListener mListener;
	int[] ids;
	String[] str;
	int layoutId;

	@SuppressWarnings("deprecation")
	public MySimpleCursorAdapter(Context context, int layout, Cursor c,
			String[] string, int[] id) {
		super(context, layout, c, string, id);
		ids = id;
		str = string;
		layoutId = layout;
		mContext = context;
		mInflater = LayoutInflater.from(context);

	}

	@Override
	public void bindView(View view, Context context, Cursor cursor) {

		TextView number = (TextView) view.findViewById(R.id.number);
		final String text = cursor.getString(cursor.getColumnIndex(str[0]));
		ImageView delete = (ImageView) view.findViewById(R.id.img);
		number.setText(text);
		delete.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mListener != null) {
					mListener.onDelClicked(text);
				}
			}
		});

	}

	@Override
	public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
		return mInflater.inflate(layoutId, arg2, false);
	}

	public void setMyAdapterListener(OnMyAdaptertListener listener) {
		mListener = listener;
	}

	public interface OnMyAdaptertListener {
		public void onDelClicked(String text);
	}

}