Gridview first position called repeatedly when scroll gridview

Gridview first position called repeatedly when scroll gridview



I am wondering why the view in first position is repeatedly called when I scroll the gridview even when I set the adapter. This causes my gridview cannot be scrolled smoothly as it repeatedly reload image.



It seems Picasso.with(context).load(file).into(viewImage); causes the repeatedly called because if I delete this line, the gridview can be scrolled smoothly.


Picasso.with(context).load(file).into(viewImage);



Any suggestions for improvement? Thanks.



Implementation for gridview array adapter


class HomeBrandCVC extends ArrayAdapter<Brand>

private Context context;
private ArrayList<Brand> brandArrayList;
private Map<Integer, File> fileMap = new HashMap<>();

public HomeBrandCVC(Context c, ArrayList<Brand> brandArrayList)
super(c, R.layout.homecvc, brandArrayList);
this.context = c;
this.brandArrayList = brandArrayList;


@Override
public View getView(int position, View convertView, ViewGroup parent)
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.homecvc, parent, false);
TextView nameLabel = (TextView) rowView.findViewById(R.id.homecvc_nameLabel);
nameLabel.setVisibility(View.INVISIBLE);
final Brand brand = brandArrayList.get(position);
nameLabel.setText(brand.name);
ImageView viewImage = (ImageView) rowView.findViewById(R.id.homecvc_viewImage);

Log.d("hellllo", String.valueOf(position));

if (fileMap.containsKey(position))
viewImage.setImageBitmap(BitmapFactory.decodeFile(fileMap.get(position).getAbsolutePath()));
else
viewImage.setImageResource(R.drawable.loadingimage);
new MyLeanCloudApp.GetImageFromDiskOrUrl(brand.imageFile, new MyLeanCloudApp.ImageHandlerGetImagesResponse()
@Override
public void processFinish(File file)
if (context != null)
if (file != null)
Picasso.with(context).load(file).into(viewImage);
fileMap.put(position, file);



).execute();

return rowView;





1 Answer
1



Always try to use ViewHolder Pattern for lists and girds. This will improves the performance of Lists and Grids. Other think its not only depend on Picasso but its also depend on your image url, you in you xml layout file, loading data, etc.


ViewHolder



Try to use ViewHolder to avoid scrolling issue and improves its performance


ViewHolder


@Override
public View getView(int position, View convertView, ViewGroup parent)

ViewHolder viewHolder = null;
if(convertView==null)
viewHolder = new ViewHolder();
convertView = inflater.inflate(R.layout.grid_item,parent,false);

convertView.setTag(viewHolder);

else
viewHolder=(ViewHolder)convertView.getTag();

viewHolder.image=(ImageView)convertView.findViewById(R.id.thumbnail);
viewHolder.title=(TextView)convertView.findViewById(R.id.title);
viewHolder.title.setText(Html.fromHtml(values.getPosts().get(position).getTitle()));

imageView.setImageResource(Imageid[position]);
return convertView;


private static class ViewHolder
public static ImageView image;
public static TextView title;



Other think is try to load your image from cash if its previously loaded when you are using Picasso. For that check this tutorial.





tried but still lagging
– Pak Ho Cheung
Sep 9 at 9:25



Required, but never shown



Required, but never shown






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Crossroads (UK TV series)

ữḛḳṊẴ ẋ,Ẩṙ,ỹḛẪẠứụỿṞṦ,Ṉẍừ,ứ Ị,Ḵ,ṏ ṇỪḎḰṰọửḊ ṾḨḮữẑỶṑỗḮṣṉẃ Ữẩụ,ṓ,ḹẕḪḫỞṿḭ ỒṱṨẁṋṜ ḅẈ ṉ ứṀḱṑỒḵ,ḏ,ḊḖỹẊ Ẻḷổ,ṥ ẔḲẪụḣể Ṱ ḭỏựẶ Ồ Ṩ,ẂḿṡḾồ ỗṗṡịṞẤḵṽẃ ṸḒẄẘ,ủẞẵṦṟầṓế