I am having a grid view ,I am passing data which I want to display in grid view to the gridview adaptor class.Now I want to remove the item when an item is long pressed.
I want to delete in onItemLongClickListener .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What you need to do is this:
Create a custom adapter for your GridView. In that adapter, provide a method for removing an item from the list of items it maintains, for example ‘void removeItem(int position)`
Call
setOnItemLongClickListenerto your grid. In this method, you get the position of the item that the long click occurred on. From this method, call the method to remove the item with the position you just received.Notify the GridView that the data has changed using
notifyDataSetchangedmethod. If you want the GridView UI to update immediately, you need to useHandlerfor this request to make sure it happens on the UI thread.