Android: How do I remove an item from a gridview, having the remaing items shuffle into place

十年热恋 提交于 2019-12-10 05:05:36

问题


BACKGROUND:
I have a grid of 36 buttons, lets say a 6 rows & 6 columns numbered 1 to 36, displayed 2 rows at a time via a GridView and custom Adapter

The grid displays fine, and all of the scrolling works properly.

QUESTION:
I want to be able to click on an item, have it removed from the grid and the remain items shuffle up into place. Currently I am able to disable the item disabled, set its visibility to INVISIBLE or GONE, but none of these will actually remove it from the display.

Suggestions?


回答1:


Specifically, you need to remove the corresponding object from the data set of the underlying adapter and then call adapter.notifyDataSetChanged(). This isn't going to provide you with an animation, though, if that was part of this question.

It may be interesting to try a tween animation for the item in question and then finally remove it from your adapter at the end. I'm not well-versed in animation, so I'm not sure how well this will work in an AdapterView.




回答2:


You should be able to update the adapter, and then call notifyDataSetChanged to force the grid view to be updated.



来源:https://stackoverflow.com/questions/5306874/android-how-do-i-remove-an-item-from-a-gridview-having-the-remaing-items-shuff

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!