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 6955125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:41:45+00:00 2026-05-27T14:41:45+00:00

I have implemented a gridview with custom adapter and the adapter inflates a layout

  • 0

I have implemented a gridview with custom adapter and the adapter inflates a layout and show two items in every element of gridview. one is imageview and another one is close button which is placed on right top of image.My problem is to remove the element from the grid when i click on the cross button. I’ve to trigger the event for two images. So i Planned to give the close button event inside the Adapter. Finally it works but i’m unable to remove the clicked position. Whenever i click the close button image it’ll remove the last element from my arraylist. Please Help me in this.

My Code is Below :

@Override
public View getView( int position, View convertView, ViewGroup parent)
{

    View MyView = convertView;



    pos=position;
    positionForCheck =(Object) pos;
    if (convertView == null)
    {           

        LayoutInflater li = (LayoutInflater) MyContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        MyView = li.inflate(R.layout.grid_item_for_bag, null);


        // Add The Image!!!
        ImageView imageSrc = (ImageView) MyView.findViewById(R.id.grid_item_bag_image);

        ImageView imageClose = (ImageView) MyView.findViewById(R.id.grid_item_bag_close);


    }   

    imageSrc.setImageResource(MyList.get(position));


    imageClose.setImageResource(R.drawable.closeicon_31x31);
    imageClose.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {   

                                    MyList.remove(position)
                notifyDataSetChanged();
            }
        });


    return MyView;
}
  • 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-05-27T14:41:46+00:00Added an answer on May 27, 2026 at 2:41 pm

    I got the output.
    the code is like the below

     @Override
    public View getView( int position, View convertView, ViewGroup parent)
    {
    
    View MyView = convertView;
    ViewHolder holder;
    
    
    pos=position;
    positionForCheck =(Object) pos;
    if (convertView == null)
    {           
    
        LayoutInflater li = (LayoutInflater) MyContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        MyView = li.inflate(R.layout.grid_item_for_bag, null);
        holder = new ViewHolder();
    
        // Add The Image!!!
        holder.imageSrc = (ImageView) MyView.findViewById(R.id.grid_item_bag_image);
    
        holder.imageClose = (ImageView) MyView.findViewById(R.id.grid_item_bag_close);
        MyView.setTag(holder);
    
    }   
     else
     {
     holder =(ViewHolder) MyView.getTag();
     }
    
    holder.imageSrc.setImageResource(MyList.get(position));
    
    holder.imageClose.setTag(position)
    holder.imageClose.setImageResource(R.drawable.closeicon_31x31);
    holder.imageClose.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v)
            {   
                int posi = Integer.parseInt(v.getTag().toString());
                MyList.remove(posi)
                notifyDataSetChanged();
            }
        });
    
    
    return MyView;
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have followed Custom Pagination article to implement the custom pagination using GridView. I
I have a gridview with the onRowDeleting method implemented. I would like to prompt
I have successfully implemented my GridView now, but, as always, the whole ASP.NET life
i am using asp.net 2008 and i have implemented the in-build Gridview Paging.But it
I'm creating a custom view derived from GridView. This contains a custom ImageView with
I have a GridView with 9 items. What I'm trying to do is when
I have implemented export data from GridView to excelsheet functionality in .net application. and
Here is my scenario, I have implemented a gridview, when the user press the
I am developing an ipad app.In this app,I have two sections-one showing a Gallery
I have a gridview displaying some images. I have implemented a ViewFlipper to navigate

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.