开发者

grab ListActivity's item position when creating a Context Menu

I've got a ListActivity with a onClickListener which succesfully captures the item's position index which I then use to grab objects of my feeding ArrayList of Document objects. I would开发者_如何学Go also like to be able to grab this position int when opening a Context Menu. How do I do that? Code snippets: My successfuly working onListItemClick

    @Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    super.onListItemClick(l, v, position, id);
    SearchResult sr = searchResults.get(position); // this is how I grab my document
    Toast.makeText(this, sr.toString(), Toast.LENGTH_SHORT).show();
}

Is there a way to grab this integer by these methods?

public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {

OR

public boolean onContextItemSelected(MenuItem item) {

Thanks guys!


Something like this:

int lastPosition = -1;


public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    AdapterView.AdapterContextMenuInfo info = 
        (AdapterView.AdapterContextMenuInfo) menuInfo;
    lastPosition = info.position;
}

public boolean onContextItemSelected(MenuItem item) {
    doStuff(lastPosition);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜