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;
}
I got the output.
the code is like the below