views:

29

answers:

1

I have an implementation that just like gmail application, but have met some problem in some case. And I tested it on the real device of the gmail application. Seems they are caused by the same reason. ListView.

Just go to the gmail application, scroll down to the last visible mail, and at this time, make sure the "loading conversation" at the bottom is still on. Then long press the last one mail, and the context menu show up. Then wait for the background email loading finish ( you can see that the scrollbar move up ). Then you do some action in the context menu, say "read the mail". However, the show up mail is not the one that I long pressed.

After some debug, I found that this should be related to ListView and its adapter's getView method, the "convert view" is reused when the context menu is shown, and in that case the listItemview has some field to record the index of the mail, while getView method is invoked, the field has been changed.

Any one can provide a better way to solve this problem ?

Thanks.

A: 

I can see encountering this problem if the content menu handler relies upon the position rather than the _ID. Particularly if you are using CursorAdapter, use the _ID value, as that (hopefully) is immutable.

CommonsWare
Thanks for the tips. However, after a more detail digg, the problem does not related to _ID/position. But I have figure out how to fix the problem: just use another variable to record the going to be operate item id when the context menu is open.