关联SimpleCursorAdapter时会自动获取”_id”列,
也就是说public void onItemClick(AdapterView<?> parent, View view,int position, long id)中的id就是数据库中对应项的_id。
根据是
SimpleCursorAdapter->ResourceCursorAdapter->CursorAdapter的构造函数
public CursorAdapter(Context context, Cursor c)
{
init(context, c, true);
}
protected void init(Context context, Cursor c, boolean autoRequery)
{
boolean cursorPresent = c != null;
mAutoRequery = autoRequery;
mCursor = c;
mDataValid = cursorPresent;
mContext = context;
mRowIDColumn = cursorPresent ? c.getColumnIndexOrThrow("_id") : -1;
mChangeObserver = new ChangeObserver();
if (cursorPresent)
{
c.registerContentObserver(mChangeObserver);
c.registerDataSetObserver(mDataSetObserver);
}
}
public long getItemId(int position)
{
if (mDataValid && mCursor != null)
{
if (mCursor.moveToPosition(position))
{
return mCursor.getLong(mRowIDColumn);
}
else
{
return 0;
}
}
else
{
return 0;
}
}
long android.database.Cursor.getLong(int columnIndex)
Returns the value of the requested column as a long.
If the native content of that column is not numeric the result will be the result of passing the column value to Long.valueOf(x).
参数:
columnIndex the zero-based index of the target column.
返回:
the value of that column as a long
CursorAdapter中的