开发者

How to remove previous view from Grid view in android

开发者 https://www.devze.com 2023-03-15 08:19 出处:网络
I am facing a problem with GridView I have created a ImageAdapter class which extends the BaseAdapter.I have written the following code for set image on grid view.

I am facing a problem with GridView I have created a ImageAdapter class which extends the BaseAdapter.I have written the following code for set image on grid view.

gridView.setAdapter(new ImageAdapter(this));

The problem is When I reload this activity it appends with previous view. Images come dynamically from URL. It is not refreshing the view. how can we remove previous view? Thanks.

Here is the ImageAdapter class code:

public class ImageAdapter extends BaseAdapter{
            Context mContext;
            public static final int ACTIVITY_CREATE = 10;
            public ImageAdapter(Context c){
                mContext = c;
            }

            public int getCount() {
                // TODO Auto-generated method stub
                return Search_List_Activity.image_me.size();
            }


            public View getView(int position, View convertView, ViewGroup parent) {
                // TODO Auto-generated method stub
                View v;

                if(convertView==null){
                    LayoutInflater li = getLayoutInflater();
                    v = li.inflate(R.layout.grid_item, null);
                    TextView tv = (TextView)v.findViewById(R.id.grid_item_text);
                    tv.setText("From  "+Search_List_Activity.min_price.get(position));
                    ImageView iv = (ImageView)v.findViewById(R.id.grid_item_image);
                    try{
                        iv.setImageBitmap(bmp[position]);
                    }
                    catch(Exception e){
                        iv.setBackgroundResource(R.drawable.no_pic_155x155);
                    }

                }
                else
                {
                    v = convertView;
      开发者_如何学运维          }
                return v;
            }

            public Object getItem(int arg0) {
                // TODO Auto-generated method stub
                return null;
            }

            public long getItemId(int arg0) {
                // TODO Auto-generated method stub
                return 0; 
            }
        }


Perhaps some where you are using any type of list which is always getting increased each time when you are creating grid view with Image Adpater. that list is used in ImageAdapter.

Thanks Deepak

0

精彩评论

暂无评论...
验证码 换一张
取 消