public View getView(int position, View view, ViewGroup group) { Log.d("PenDataAdapter", "getView(" + position + ") called."); // calculate position int rowIndex = position / rowCount; int columnIndex = position % rowCount; Log.d("PenDataAdapter", "Index : " + rowIndex + ", " + columnIndex); GridView.LayoutParams params = new GridView.LayoutParams( GridView.LayoutParams.FILL_PARENT, GridView.LayoutParams.FILL_PARENT); // create a Pen Image int areaWidth = 10; int areaHeight = 20; Bitmap penBitmap = Bitmap.createBitmap(areaWidth, areaHeight, Bitmap.Config.ARGB_8888); Canvas penCanvas = new Canvas(); penCanvas.setBitmap(penBitmap); Paint mPaint = new Paint(); mPaint.setColor(Color.WHITE); penCanvas.drawRect(0, 0, areaWidth, areaHeight, mPaint); mPaint.setColor(Color.BLACK); mPaint.setStrokeWidth((float) pens[position]); penCanvas.drawLine(0, areaHeight / 2, areaWidth - 1, areaHeight / 2, mPaint); BitmapDrawable penDrawable = new BitmapDrawable(mContext.getResources(), penBitmap); // create a Button with the color TitleBitmapButton aItem = new TitleBitmapButton(mContext); aItem.setText(" "); aItem.setLayoutParams(params); aItem.setPadding(4, 4, 4, 4); aItem.setBackgroundDrawable(penDrawable); aItem.setHeight(48); aItem.setTag(pens[position]); // set listener aItem.setOnClickListener( new OnClickListener() { public void onClick(View v) { if (PenPaletteDialog.mSelectedListener != null) { PenPaletteDialog.mSelectedListener.onPenSelected(((Integer) v.getTag()).intValue()); } ((PenPaletteDialog) mContext).finish(); } }); return aItem; }