Yoav
Yoav

Reputation: 645

ListViewAdapter image loading

I have a listview with a custom adapter. Each listview item has an ImageView. The ImageView is being taken from the camera or gallery, and can be changed.

I have this code in the Adapter:

@Override
    public View getView(    int         position, 
                            View        convertView, 
                            ViewGroup   parent ) 
    {
          ViewHolder    holder = new ViewHolder();

          if (convertView == null) 
          {
              convertView = mInflater.inflate(R.layout.instruction_list_view_entry, null);
              holder.instructionIndex   = (TextView) convertView.findViewById( R.id.listUp_InstructionNumberTextBoxId );
              holder.instructionText    = (TextView) convertView.findViewById( R.id.listUp_InstructioTextTextBoxId );
              holder.instructionImage   = (ImageView)convertView.findViewById( R.id.listUp_InstructionImageViewId );

              holder.instructionIndex.setTypeface(  MyApp.Fonts.ERAS_BOLD );
              holder.instructionIndex.setTextSize(  MyApp.Fonts.INSTRUCTION_ID_TEXT_SIZE );

              holder.instructionText.setTypeface(  MyApp.Fonts.ARIAL );
              holder.instructionText.setTextSize(  MyApp.Fonts.RUNNING_TEXT_SIZE );
              holder.instructionText.setTextColor( Color.BLACK );
          }
          else
          {
              holder = (ViewHolder) convertView.getTag();
          }

          if( super.getItem(position) != null )
          {
              holder.instructionIndex.setText( Integer.toString(getItem(position).getIndex() ) );

              holder.instructionText.setText( getItem(position).getText() );

              if( getItem( position ).GetImageUploadItem().isValid() )
              {
                  mImageLoader.DisplayImage(    getItem( position ).GetInstructionImageLocation(), 
                                                getItem( position ).IsUsingLocalPictures(),
                                                mContext, 
                                                holder.instructionImage );

                  holder.instructionImage.setVisibility( View.VISIBLE );
              }
              else
              {
                  holder.instructionImage.setVisibility( View.GONE );
              }

              convertView.setTag(holder);
          } 

          return convertView;
    }

    @Override
    public boolean isEnabled(int position) 
    {
        return mCanBeEnabled;
    }

    static class ViewHolder 
    {
          TextView  instructionIndex;
          TextView  instructionText;
          ImageView instructionImage;
    }

The ImageLoader is the class that loads the images from th file.

The problem I see is that when having multiple rows with pictures - the scrolling is not good, not smooth.

I found out that the ImageLoading is being created all the time. How can I fix it? Please note that the image can be changed and then needs to be reloaded. Maybe if I put to the data in the adapter a flag of image changed and only the load it?

Any other ideas?

Upvotes: 1

Views: 181

Answers (1)

TryTryAgain
TryTryAgain

Reputation: 7830

I would suggest you look into Caching your ImageLoader:

Hopefully this post will point you in that direction: Android: Help in adapting ListView adapter with an ImageLoader Class

Upvotes: 1

Related Questions