ListView 之 OnItemClickListener

关联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中的


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值