/**
* 获取某行某列信息
* @param info
* @param column
* @return
*/
public static int getIntValue(ItemInfo info, String column) {
ContentResolver cr = LauncherApplication.getApp().getContentResolver();
final Cursor c = cr.query(CONTENT_URI, new String[]{column}, ID + "=" + info.id, null, null);
if (null == c) {
return 0;
}
final int index = c.getColumnIndex(column);
int value = 0;
if (c.moveToFirst()) {
c.getInt(index);
}
c.close();
return value;
}
注:cr.query()中new String[]{column}参数指定返回那些列信息, 如果返回所有列, 赋值null, 但是这样效率比较低
android.database.cursorindexoutofboundsexception异常发生在c.getInt(index);这行代码, 需要加上if (c.moveToFirst()) {}这个判断条件即可