I am currently working on a project showing mobile phones and its price. My project contains two gridviews. The first gridview displays a list of mobile brands with text (brand names) and an image. When we click on the content in the first gridview, the second gridview is displayed with a list of mob images and the price of a particular brand. My project is successful, but I have used so many adapter classes for them. My question is: is it possible to use one adapter class with several arrays of images to display images of different brands of mobs.
The current mine adapter classes are listed below:
Iphone mob adapter class
public class ImageAdapter1 extends BaseAdapter {
private Context mContext;
public ImageAdapter1(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Integer[] mThumbIds = {
R.drawable.iphone1, R.drawable.iphone2,
R.drawable.iphone3, R.drawable.iphone4,
R.drawable.iphone5, R.drawable.iphone6
};
}
Samsung adapter class
public class ImageAdapter2 extends BaseAdapter {
private Context mContext;
public ImageAdapter2(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if (convertView == null) {
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8, 8, 8, 8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
private Integer[] mThumbIds = {
R.drawable.samsung1, R.drawable.samsung2,
R.drawable.samsung3, R.drawable.samsung4
};
}
if getView() . :( . , .