Android GridView ImageAdapter

public class ImageAdapter extends BaseAdapter {
 
 private Context _context = null;
 private PhotoItem[] _photoArray = null;
 
 public ImageAdapter( Context ctx, PhotoItem[] imageArray )
 {
  _context = ctx;
  _photoArray = imageArray;
 }

 @Override
 public int getCount() {
  // TODO Auto-generated method stub
  return _photoArray.length;
 }

 @Override
 public PhotoItem getItem(int pos) {
  // TODO Auto-generated method stub
  return _photoArray[ pos ];
 }

 @Override
 public long getItemId(int position) {
  // TODO Auto-generated method stub
  return 0;
 }

 @Override
 public View getView(int pos, View convertView, ViewGroup parent) {
  // TODO Auto-generated method stub
  View gridView;

  if ( convertView == null ) // if it's not recycled, initialize some attribute
  { 
   LayoutInflater vi = (LayoutInflater) _context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
   gridView = vi.inflate( R.layout.image_item, null);
   
   ImageView imageView = (ImageView)gridView.findViewById( R.id.imageItemView );
   imageView.setImageDrawable( _photoArray[ pos ].getPhoto() );
  }
  else
  {
   gridView = (View)convertView;
  }
 
  return gridView;
 }

}

http://www.mkyong.com/android/android-gridview-example/

Comments

Popular posts from this blog

Drawing textured cube with Vulkan on Android

glTF loader for Android Vulkan

C++ unit testing & CI integration in GitHub (I/2)