问题
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