0

I am using horizontal progress bar in grid view but when I scroll the position of the progress bar change to some other view.

I am also used view holder to solve this issue but it not working.

can some one guide me why this is happening.

Hear is my code:

public View getView(final int position, View convertView, ViewGroup parent) {
        // ViewHolder holder = null;

        if (convertView == null) {
            viewHolder = new ViewHolderItem();

            LayoutInflater inflater = (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.gridviewcell, null);

            viewHolder.downloadbutton = (ImageView) convertView
                    .findViewById(R.id.imgBtnbookdownload);
            viewHolder.download_book_pro = (ProgressBar) convertView
                    .findViewById(R.id.progressBar_ingridcell);

            convertView.setTag(viewHolder);

        } else {
            viewHolder = (ViewHolderItem) convertView.getTag();
        }

            Log.d("position",""+position);
        tv_ot_edition_name = (TextView) convertView
                .findViewById(R.id.ot_edition_name);
        tv_ot_edition_name.setText(books.get(position).getOt_edition_name());

        tv_edition_description = (TextView) convertView
                .findViewById(R.id.ot_edition_description);

        Typeface face = Typeface.createFromAsset(context.getAssets(),
                "HelveticaBold.ttf");
        tv_ot_edition_name.setTypeface(face);
        tv_edition_description.setTypeface(face);
        tv_edition_description.setText(books.get(position)
                .getOt_edition_description());

        book_image = (ImageView) convertView.findViewById(R.id.imageView1);

        final Download_book_content download = new Download_book_content(
                context, position, book_image, viewHolder.download_book_pro,
                books, yourDir, imageLoader, string_testament, postion_ot,
                viewHolder.downloadbutton);

        viewHolder.downloadbutton.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                check_netconnection check = new check_netconnection(context);
                boolean status = check.findnet();
                if (status == true) {

                    download.startdownload();

                } else {
                    Toast.makeText(context,
                            "Please check your internet connection",
                            Toast.LENGTH_SHORT).show();
                }

            }
        });

        // imageLoader.displayImage(books.get(position).getImage_url(),
        // book_image, options);
        imageLoader.displayImage(books.get(position).getImage_url(),
                book_image, options, new ImageLoadingListener() {
                    @Override
                    public void onLoadingStarted(String imageUri, View view) {

                    }

                    @Override
                    public void onLoadingFailed(String imageUri, View view,
                            FailReason failReason) {

                    }

                    @Override
                    public void onLoadingComplete(String imageUri, View view,
                            Bitmap loadedImage) {
                        Animation anim = AnimationUtils.loadAnimation(context,
                                android.R.anim.fade_in);
                        anim.setDuration(1500);
                        book_image.setAnimation(anim);
                        anim.start();
                    }

                    @Override
                    public void onLoadingCancelled(String imageUri, View view) {

                    }
                });


        viewHolder.downloadbutton.setImageResource(books.get(position)
                .getDownloadbtn_resid());


        return convertView;
    }

Thank's in advance.

ShreeshaDas
  • 2,042
  • 2
  • 17
  • 36

1 Answers1

0

I solved this by overriding this two methods in the Adapter of the gridview. On the downside, this code tells the Adapter to never recycle views. Can cause sluggish UI and lack of responsiveness.

@Override
public int getViewTypeCount(){
    return getCount();
}

@Override
public int getItemViewType(int position){
    return position;
}
Penta
  • 241
  • 2
  • 4
  • 12
  • This is not an exact way of handling this issue. You should maintain the selection of the views - [Check this Thread](http://stackoverflow.com/a/7738854/726863) – Lalit Poptani May 10 '14 at 08:54