Back to project page digitalcampus.
The source code is released under:
MIT License
If you think the Android project digitalcampus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.llenguatges.digitalcampus.adapters; /* www . j a v a2s . c o m*/ 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 com.llenguatges.digitalcampus.R; import com.llenguatges.digitalcampus.objects.Item; public class CustomGridViewAdapter extends ArrayAdapter<Item> { Context context; int layoutResourceId; ArrayList<Item> data = new ArrayList<Item>(); /** * Constructor * @param context * @param layoutResourceId * @param data */ public CustomGridViewAdapter(Context context, int layoutResourceId, ArrayList<Item> data) { super(context, layoutResourceId, data); this.layoutResourceId = layoutResourceId; this.context = context; this.data = data; } /** * Get a View that displays the data at the specified position in the data set. * @param position * @param converView * @param parent */ public View getView(int position, View convertView, ViewGroup parent) { View row = convertView; RecordHolder holder = null; if (row == null) { LayoutInflater inflater = ((Activity) context).getLayoutInflater(); row = inflater.inflate(layoutResourceId, parent, false); holder = new RecordHolder(); holder.txtTitle = (TextView) row.findViewById(R.id.item_text); holder.imageItem = (ImageView) row.findViewById(R.id.item_image); row.setTag(holder); } else { holder = (RecordHolder) row.getTag(); } Item item = data.get(position); holder.txtTitle.setText(item.getTitle()); holder.imageItem.setImageBitmap(item.getImage()); switch (position) { case 0: holder.imageItem.setImageResource(R.drawable.ic_action_group); break; case 1: holder.imageItem.setImageResource(R.drawable.ic_action_storage); break; case 2: holder.imageItem.setImageResource(R.drawable.ic_action_event); break; case 3: holder.imageItem.setImageResource(R.drawable.ic_action_undo); break; default: break; } return row; } static class RecordHolder { TextView txtTitle; ImageView imageItem; } }