listview自定义CursorAdapter

定义listview并获取cur:

listNote = (ListView)findViewById(android.R.id.list);
cur = getContentResolver().query(uri,null,null,null,null);

使用SimpleCursorAdapter

adapter = new SimpleCursorAdapter(this,R.layout.note_item,cur,
new String[]{"title","date"},
new int[]{R.id.note_list_title,R.id.note_list_time});

listNote.setAdapter(adapter);

如何使用自定义的CursorAdapter呢?

adapter = new myCursorAdapter(this, cur);
listNote.setAdapter(adapter);

class myCursorAdapter extends CursorAdapter{ private LayoutInflater mInflater; private Context mContext; public myCursorAdapter(Context context, Cursor c) { super(context, c); mContext = context; mInflater = LayoutInflater.from(context); // TODO Auto-generated constructor stub } @Override public void bindView(View view, Context context, Cursor cursor) { TextView noteTitle = (TextView) view.findViewById(R.id.note_list_title); TextView noteData = (TextView) view.findViewById(R.id.note_list_time); Log.d("xxxx", "cur="+cursor.getCount()+",c_count="+cursor.getColumnCount()); noteTitle.setText(cur.getString(3)); noteData.setText(cur.getLong(2)); //super.bindView(view, context, cursor); } @Override public View newView(Context arg0, Cursor arg1, ViewGroup arg2) { return mInflater.inflate(R.layout.note_item, arg2, false); } }

Cursor c = getContentResolver().query(uri, null, "_id="+uri.getPathSegments().get(1), null, null);
c.moveToFirst();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值