Android Open Source - ImageSearcher2 Image Result Array Adapter






From Project

Back to project page ImageSearcher2.

License

The source code is released under:

Apache License

If you think the Android project ImageSearcher2 listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.imagesearcher;
/*  ww  w  .j a  v a  2 s  .c  o m*/
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.loopj.android.image.SmartImageView;

/**
 * @author Ed
 * 
 * ArrayAdapter to adapt array of ImageResult into image views.
 *
 */
public class ImageResultArrayAdapter extends android.widget.ArrayAdapter<ImageResult>
{
  public ImageResultArrayAdapter(Context context, List<ImageResult> objects)
  {
    // use our grid image layout for grid items
    super(context, R.layout.grid_item_image, objects);
  }

  @Override
  public View getView(int position, View convertView, ViewGroup parent)
  {
    final ImageResult theImageResult = this.getItem(position);
    SmartImageView theSmartImageView;
    
    if(null == convertView)
    {
      // create a new view
      LayoutInflater theLayoutInflater = LayoutInflater.from(getContext());
      theSmartImageView = (SmartImageView)theLayoutInflater.inflate(R.layout.grid_item_image, parent, false);

      // set url and return it.  The image is loaded asynchronously
      theSmartImageView.setImageUrl(theImageResult.getThumbUrl());
      theSmartImageView.setTag(theImageResult.getThumbUrl());  // remember the url
    }
    else  // use the pre-existing view
    {
      theSmartImageView = (SmartImageView)convertView;
      
      // if this url is different, reload the image
      if(!theImageResult.getThumbUrl().equals(theSmartImageView.getTag()))
      {
        theSmartImageView.setImageResource(android.R.color.darker_gray);  // make the image transparent

        // set url and return it.  The image is loaded asynchronously
        theSmartImageView.setImageUrl(theImageResult.getThumbUrl());
        theSmartImageView.setTag(theImageResult.getThumbUrl());  // remember the url
      }
    }
    return theSmartImageView;
  }
  
  

}




Java Source Code List

com.example.imagesearcher.ActivityRequestCodes.java
com.example.imagesearcher.EndlessScrollListener.java
com.example.imagesearcher.ImageGridActivity.java
com.example.imagesearcher.ImageResultArrayAdapter.java
com.example.imagesearcher.ImageResult.java
com.example.imagesearcher.ImageViewActivity.java
com.example.imagesearcher.SearchSettingsActivity.java
com.example.imagesearcher.SearchSettings.java