Question

I have a listview row that has Imageview component. In the getview() method i'm doing some checks and according to them i change the imageview with setBackgroundResource() method.

I have a problem when I run there are rows that the imageview component contains several images on each other.

is there anything i can do to fix this problem? (i change the BackgroundResource one time for each row (position).

Was it helpful?

Solution

I cant see some code but I think you should use a ViewHolder.

Example:

public View getView(int position, View convertView, ViewGroup parent) {            


   ViewHolder holder;                       

   if (convertView == null) {                

    convertView = mInflater.inflate(R.layout.sample, null);             
    holder = new ViewHolder();                
    holder.name = (TextView) convertView.findViewById(R.id.text);               
    holder.icon = (ImageView) convertView.findViewById(R.id.icon);                
    convertView.setTag(holder);            
   } else {                


    holder = (ViewHolder) convertView.getTag();

   }            
   holder.name.setText(myElements.get(id)); 
   holder.icon.setImageBitmap( mIcon1 );

   return convertView;
  }  

static class ViewHolder {            
    TextView name;            
    ImageView icon;        
} 

If this doesnt help load the images asynchronously. I would recommend Picasso. http://square.github.io/picasso/

Regards Nils

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top