2011-12-16 25 views
1

我有点新,所以请耐心等待,如果这看起来像一个愚蠢的问题。 我目前使用onListItemClick来检索所选ListItem的ID。 我对int位置和long id参数之间的差异感到困惑。 它是一样的吗?有人可以好好解释一下。先进的谢谢你。简单的onListItemClick()参数

@Override 
protected void onListItemClick(ListView l, View v, int position, long id) { 
    Cursor c = ((SimpleCursorAdapter)l.getAdapter()).getCursor(); 
    c.moveToPosition(position); 
    int _id = (int)c.getLong(0); 
    //int _id = (int) id; 
    String word_id = Integer.toString(_id); 

    Toast.makeText(this, word_id, Toast.LENGTH_SHORT).show(); 
} 

我打算使用简单的按钮,而不是上述方法,但我不知道如何检索活动的ListView。

+0

该位置是视图在ListView中的位置(第一个条目的位置为0)。 id是识别位置的数据行)。例如,id可能是数据库中某一行的行标识。通过这个你可以识别出这个位置的信息。 – 2011-12-16 16:54:14

回答

3
l The ListView where the click happened 
v The view that was clicked within the ListView 
position The position of the view in the list 
id The row id of the item that was clicked 
+0

所以,如果我从一个数据库打印随机条目,并试图检索一个特定的行,我应该使用ID而不是位置?谢谢! – 2011-12-16 18:28:53