开发者

A bug in Android listview and adapter

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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜