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

StackOverflow https://stackoverflow.com/questions/5306874

  •  24-10-2019
  •  | 
  •  

سؤال

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?

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top