//根據(jù)音樂ID查詢音樂實(shí)體對象 public MusicInfo queryById(long id) { ????Cursor cursor = cr.query(Media.EXTERNAL_CONTENT_URI,? ????????????????????????????musicContent, "_id=?", new String[]{id+""}, null); ????if(cursor.moveToNext()) { ????????Log.i(TAG, "====="); ????????MusicInfo info=new MusicInfo(); ????????info._id= cursor.getInt(cursor.getColumnIndex(Media._ID)); ????????info.displayName=cursor.getString(cursor.getColumnIndex(Media.DISPLAY_NAME)); ????????info.title=cursor.getString(cursor.getColumnIndex(Media.TITLE)); ????????info.duration=cursor.getLong(cursor.getColumnIndex(Media.DURATION)); ????cursor.close(); ????//返回結(jié)果 ????return info; ????}else{ ????? ?//沒有數(shù)據(jù) ????cursor.close(); ????return null; ????} }
1 回答

星箜下
TA貢獻(xiàn)34條經(jīng)驗(yàn) 獲得超10個(gè)贊
進(jìn)不去說明Cursor沒數(shù)據(jù), 你看看是不是_id是integer型的,你這里是new String(id+"") ,換成new Integer(id),不知道SQLite能不能自動這樣轉(zhuǎn)換。
添加回答
舉報(bào)
0/150
提交
取消