Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8603723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:23:26+00:00 2026-06-12T02:23:26+00:00

I have implemented my code to delete and change the view on long press

  • 0

I have implemented my code to delete and change the view on long press of a gridview. Here is my updated code. Now I have a problem when I long press then I have to change all the items image( I am adding a view more to all on long press – i.e a cross button)

On the Click of that cross button I want to delete that item. Please help me.

 public class Deletable extends Activity
{
    private LayoutInflater inflater = null;

    Boolean checkLong = false;

    Vector<Integer> mThumbsID =  new Vector<Integer>();


    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.grid_view);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        final ImageAdapter adapter = new ImageAdapter(this);
        gridview.setAdapter(adapter);

        inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mThumbsID.setSize(9);

        gridview.setOnItemLongClickListener(new OnItemLongClickListener() {

            @Override
            public boolean onItemLongClick(AdapterView<?> parent, View strings,
                    int position, long id) {
                // TODO Auto-generated method stub

                Toast.makeText(Deletable.this, "Deletable "+ position, Toast.LENGTH_SHORT).show();
                checkLong = true;
                //adapter.removeitem(position);
                adapter.notifyDataSetChanged();
                return false;

            }
        });


        /*gridview.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                // TODO Auto-generated method stub

                checkLong = false;
                adapter.notifyDataSetChanged();

            }
        });*/
    }

    public class ImageAdapter extends BaseAdapter
    {
        private Context mContext;

        public ImageAdapter(Context c)
        {
            mContext = c;
        }

        public int getCount()
        {

            return mThumbsID.size();
        }

        public Object getItem(int position)
        {
            return null;
        }

        public long getItemId(int position)
        {
            return 0;
        }

        public void removeitem(int position){
            mThumbsID.remove(position);

        }

        // create a new ImageView for each item referenced by the Adapter
        public View getView(final int position, View convertView, ViewGroup parent)
        {
            View vi = convertView;
            ViewHolder holder =  new ViewHolder();

            if (vi == null) {
                vi = inflater.inflate(R.layout.custom_gridview, null);
            }

            holder.productImage = (ImageView)vi.findViewById(R.id.gv_item);
            holder.delete_icon = (ImageView)vi.findViewById(R.id.imageView1);

            holder.productImage.setImageResource(R.drawable.ic_launcher);


            if(checkLong==true){

                holder.delete_icon.setVisibility(View.VISIBLE);
                holder.delete_icon.setImageResource(R.drawable.cross);
              /*  holder.delete_icon.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View arg0) {
                        // TODO Auto-generated method stub

                        mThumbsID.remove(position);

                    }
                });
*/
            }

            else{

                holder.delete_icon.setVisibility(View.INVISIBLE);

            }

            /*if (convertView == null)
            {
                imageView = new ImageView(mContext);
                imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(8, 8, 8, 8);
            }
            else
            {
                imageView = (ImageView) convertView;
            }
            imageView.setImageResource(R.drawable.ic_launcher);*/
            return vi;
        }


          class ViewHolder
            {
                //TextView tvBrandName;
                ImageView productImage,delete_icon;
            }



    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T02:23:27+00:00Added an answer on June 12, 2026 at 2:23 am

    You need to remove the corresponding object from the data set of the underlying adapter (mThumbIds) and then call adapter.notifyDataSetChanged()

    You can store your data in a Vector like:

    Vector<Integer> mThumbIds = new Vector<Integer>();
    

    Initialize it like:

    for (int i = 0; i < mThumbIds.size(); i++) {
                mThumbIds.add(R.drawable.ic_launcher);
            }
    

    In the removeitem():

    public void removeitem(int position){
        mThumbIds.remove(position);
    
        }
    

    Then to delete..

    public boolean onItemLongClick(AdapterView<?> parent, View strings,
                    int position, long id) {
                // TODO Auto-generated method stub
    
                Toast.makeText(Deletable.this, "Deletable "+ position, Toast.LENGTH_SHORT).show();
                adapter.removeitem(position);
                adapter.notifyDataSetChanged();
                return false;
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have implemented code like here but it's not working for iOS 5.0, it
Im looking to programmatically delete from a GridView . I have implemented the gridview's
I have implemented the code in Devise call backs in my application controller. First
FOR ANYONE INTERESTED: I have implemented the code for the behaviour I am looking
I have this code implemented and I like how straight forward it is because
I have implemented the image upload code using jquery php in my php web
I have implemented correctly bump's api, and added this code: - (void) configureBump {
I have implemented one matrix multiplication with boost::numeric::ublas::matrix (see my full, working boost code
I've have already implemented pagination using the following code: public Paginacao<Anuncio> consultarPaginado(int pagina, Integer
I have my application designed with Repository pattern implemented and my code prepared for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.