public class GalleryAdapter extends BaseAdapter {
// private LayoutInflater mLayoutInflater;
private ArrayList<String> alstImage;
private Context mContext;
public GalleryAdapter(Context mContext, ArrayList<String> alstImage) {
// this.mLayoutInflater = LayoutInflater.from(mContext);
this.mContext = mContext;
this.alstImage = alstImage;
}
public int getCount() {
return alstProductImageThumb.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@SuppressWarnings("deprecation")
public View getView(int position, View convertView, ViewGroup parent) {
// convertView = mLayoutInflater.inflate(R.layout.gallery_adapter,
// null);
// ImageView mGalleryImage =
// (ImageView)convertView.findViewById(R.id.mGalleryImage);
// System.out.println("alstProductImageThumb="+alstImage.get(position).toString());
// mImageFetcher.loadImage(alstProductImageThumb.get(position),
// mGalleryImage);
// return convertView;
ImageView imagView = new ImageView(mContext);
System.out.println("alstProductImageThumb="
+ alstProductImageThumb.get(position).toString());
mImageFetcher.loadImage(alstProductImageThumb.get(position),
imagView);
// i.setImageResource(alstProductImageURL.get(position));
imagView.setAdjustViewBounds(true);
imagView.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// i.setBackgroundResource(R.drawable.picture_frame);
return imagView;
}
}
//In Gallery class
gallery = (Gallery) v.findViewById(R.id.gallery);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
MarginLayoutParams mlp = (MarginLayoutParams) gallery.getLayoutParams();
mlp.setMargins((int) -(metrics.widthPixels/3), mlp.topMargin, mlp.rightMargin,mlp.bottomMargin);
mGalleryAdapter = new GalleryAdapter(getActivity(),
alstProductImageThumb);
gallery.setAdapter(mGalleryAdapter);
gallery.setSelection(1);
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mImageFetcher.loadImage(alstProductImageURL.get(arg2)
.toString(), t1ContentImg);
}
});
// In xml
======
<Gallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@android:color/transparent"
android:spacing="5dp" />
// private LayoutInflater mLayoutInflater;
private ArrayList<String> alstImage;
private Context mContext;
public GalleryAdapter(Context mContext, ArrayList<String> alstImage) {
// this.mLayoutInflater = LayoutInflater.from(mContext);
this.mContext = mContext;
this.alstImage = alstImage;
}
public int getCount() {
return alstProductImageThumb.size();
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
@SuppressWarnings("deprecation")
public View getView(int position, View convertView, ViewGroup parent) {
// convertView = mLayoutInflater.inflate(R.layout.gallery_adapter,
// null);
// ImageView mGalleryImage =
// (ImageView)convertView.findViewById(R.id.mGalleryImage);
// System.out.println("alstProductImageThumb="+alstImage.get(position).toString());
// mImageFetcher.loadImage(alstProductImageThumb.get(position),
// mGalleryImage);
// return convertView;
ImageView imagView = new ImageView(mContext);
System.out.println("alstProductImageThumb="
+ alstProductImageThumb.get(position).toString());
mImageFetcher.loadImage(alstProductImageThumb.get(position),
imagView);
// i.setImageResource(alstProductImageURL.get(position));
imagView.setAdjustViewBounds(true);
imagView.setLayoutParams(new Gallery.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
// i.setBackgroundResource(R.drawable.picture_frame);
return imagView;
}
}
//In Gallery class
gallery = (Gallery) v.findViewById(R.id.gallery);
DisplayMetrics metrics = new DisplayMetrics();
getActivity().getWindowManager().getDefaultDisplay().getMetrics(metrics);
MarginLayoutParams mlp = (MarginLayoutParams) gallery.getLayoutParams();
mlp.setMargins((int) -(metrics.widthPixels/3), mlp.topMargin, mlp.rightMargin,mlp.bottomMargin);
mGalleryAdapter = new GalleryAdapter(getActivity(),
alstProductImageThumb);
gallery.setAdapter(mGalleryAdapter);
gallery.setSelection(1);
gallery.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
mImageFetcher.loadImage(alstProductImageURL.get(arg2)
.toString(), t1ContentImg);
}
});
// In xml
======
<Gallery
android:id="@+id/gallery"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@android:color/transparent"
android:spacing="5dp" />
No comments:
Post a Comment