This example is very similar to the previous example. The getView of ImageAdapter also uses ImageView, but the data source is a group of photos in the resource file.
[Java]
Public View getView (int position, View convertView,
ViewGroup parent ){
ImageView imageView;
If (convertView = null ){
ImageView = new ImageView (mContext );
ImageView. setLayoutParams (new GridView. LayoutParams (45, 45 ));
ImageView. setAdjustViewBounds (false );
ImageView. setScaleType (ImageView. ScaleType. CENTER_CROP );
ImageView. setPadding (8, 8, 8, 8 );
} Else {
ImageView = (ImageView) convertView;
}
ImageView. setImageResource (mThumbIds [position]);
Return imageView;
}
Public View getView (int position, View convertView,
ViewGroup parent ){
ImageView imageView;
If (convertView = null ){
ImageView = new ImageView (mContext );
ImageView. setLayoutParams (new GridView. LayoutParams (45, 45 ));
ImageView. setAdjustViewBounds (false );
ImageView. setScaleType (ImageView. ScaleType. CENTER_CROP );
ImageView. setPadding (8, 8, 8, 8 );
} Else {
ImageView = (ImageView) convertView;
}
ImageView. setImageResource (mThumbIds [position]);
Return imageView;
}
If necessary, you can customize the Layout of a View. For example, if an ImageView is contained, next you can create a TextView, expand the layout in the getView of the ImageAdapter, and set the ImageView as a photo, set TextView to the photo name. In this case, the GridView is displayed in a grid, but each grid or photograph is displayed, and the name of the photograph is displayed below the photograph, similar to App Launcher.
Author: mapdigit