Copyright (c) 2014 Ford Motor Company
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are me...
If you think the Android project diagnostic-tool 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.openxc.openxcdiagnostic.menu;
//www.java2s.comimport android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
publicclass GridImageAdapter extends BaseAdapter {
private Context mContext;
privatedouble screenWidth;
privatedouble screenHeight;
privateInteger[] images;
privateInteger initialBackground;
public GridImageAdapter(Context c, Integer[] img, Integer backgrnd) {
mContext = c;
images = img;
initialBackground = backgrnd;
screenHeight = c.getResources().getDisplayMetrics().heightPixels;
screenWidth = c.getResources().getDisplayMetrics().widthPixels;
}
publicint getCount() {
return images.length;
}
public Object getItem(int position) {
return null;
}
publiclong getItemId(int position) {
return 0;
}
// create a new ImageView for each item referenced by the Adapter
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
int pad = 20;
if (convertView == null) { // if it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams((int)(screenWidth/3), (int)(screenHeight/4)));
imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
imageView.setPadding(pad, pad, pad, pad);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(images[position]);
imageView.setBackground(mContext.getResources().getDrawable(initialBackground));
return imageView;
}
}