I have created one gridview and use custom adapter for that. I added two images inside grid view.one is image and another one looks like close button. My plan is to remove the item from the gridview if we click the close button and it’s working.I have one textview above gridview to show number of items in gridview.But I’m not able to update the number of items text view while deleting. Please help me to find how to update User Interface. My code is like below
public View getView( int position, View convertView, ViewGroup parent)
{
View MyView = convertView;
pos=position;
if (convertView == null)
{
LayoutInflater li = (LayoutInflater) MyContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
MyView = li.inflate(R.layout.grid_item_for_bag, null);
ImageView iv = (ImageView) MyView.findViewById(R.id.grid_item_bag_image);
iv.setImageResource(R.drawable.sampleImage);
ImageView close = (ImageView) MyView.findViewById(R.id.grid_item_bag_close);
close.setImageResource(R.drawable.closeicon);
close.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
BagList.deleteItem(pos);
notifyDataSetChanged();
}
});
}
return MyView;
}
Assuming You have reference to Your text view somewhere in activity which has the grid.
The main idea – to have own DataSetObserver on Your adapter.
It should looks like the following code: