package uk.co.blatech.blaupload.ui; import java.util.ArrayList; import android.app.Activity; import android.content.Context; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.TextView; import uk.co.blatech.blaupload.R; import uk.co.blatech.blaupload.data.ImageItem; public class GridViewAdapter extends ArrayAdapter { private Context context; private int layoutResourceId; private ArrayList data = new ArrayList(); public GridViewAdapter(Context context, int layoutResourceId, ArrayList data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } @Override public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; ViewHolder holder; if (row == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new ViewHolder(); holder.imageTitle = (TextView) row.findViewById(R.id.thumbtitle); holder.image = (ImageView) row.findViewById(R.id.thumbimage); row.setTag(holder); } else { holder = (ViewHolder) row.getTag(); } ImageItem item = (ImageItem) data.get(position); holder.imageTitle.setText(item.getTitle()); holder.image.setImageBitmap(item.getImage()); return row; } static class ViewHolder { TextView imageTitle; ImageView image; } }