GridView with setting ProgressBar Invisible

My app contains a grid view that downloads images from the web and then displays them on the image , and until progressBars are visible. Note that all grid images have their own progressbar .

After the download is complete, the images are displayed and then the progress bar is invisible.

My code: -

public class MyAdapter extends BaseAdapter {

            @Override
            public int getCount() {
                // TODO Auto-generated method stub
                return data.size();
            }

            @Override
            public String getItem(int arg0) {
                // TODO Auto-generated method stub
                return data.get(arg0);
            }

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

            public class ViewHolder
            {

                ImageView image;
                ProgressWheel pb;
            }

            @Override
            public View getView(int arg0, View arg1, ViewGroup arg2) 
            {
                View vi = arg1;
                final ViewHolder holder;

                if(arg1==null)
                {
                    LayoutInflater inflater = (LayoutInflater) itemgridsub.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    vi = inflater.inflate(R.layout.gridsubitems, arg2,false);

                    holder = new ViewHolder();

                    holder.pb=(ProgressWheel)vi.findViewById(R.id.pbsub);

                holder.image=(ImageView)vi.findViewById(R.id.gridsub_iv);

                    Typeface type = Typeface.createFromAsset(getAssets(), "fonts/comic.ttf");

                    vi.setTag(holder);
                }
                else{
                    holder=(ViewHolder)vi.getTag();
                }

                Picasso.with(getApplicationContext())
               .load(link)
               .fit().centerCrop().into(holder.image,new Callback(){

                @Override
                public void onError() {
                    // TODO Auto-generated method stub
                    Toast.makeText(getApplicationContext(), "Oops Downloading Failed.\nPlease Try Again.", Toast.LENGTH_LONG);
                }

                @Override
                public void onSuccess() {
                    // TODO Auto-generated method stub
                    holder.pb.setVisibility(View.INVISIBLE);
                }

            });


                return vi;
            }

           }

      

My problem: -

Getting started, loading starts, all control panels are displayed over the image, and then after images are loaded, they are displayed in a grid. But at position 0, i.e. The first item on the grid, the progress bar keeps showing.

All other elements only display images as their progress bar is invisible, but the first element shows an image as well as a progress bar.

Why does this only happen for the first step of progress? What a mistake here.

Thank.

+3


source to share





All Articles