@Override public View getView(int position, View convertView, ViewGroup parent) { LayoutInflater layoutInflater = LayoutInflater.from(context); View item = null; if (convertView == null) { item = layoutInflater.inflate(R.layout.gridview_item_paintingcategory, parent, false); item.setLayoutParams(new GridView.LayoutParams(calcGridItemWidth, calcGridItemWidth)); } else { item = convertView; } final Painting painting = paintingCategory.get(position); ImageView imageView = (ImageView) item.findViewById(R.id.itemImage); InputStream inputStream = AssetsUtil.readAssetsFile(context, painting.getIcon()); Bitmap bitmap = BitmapUtil.decodeSampledBitmapFromStream(inputStream, 100, 100); imageView.setImageBitmap(bitmap); TextView textView = (TextView) item.findViewById(R.id.itemText); textView.setText(painting.getName()); ImageView imageViewPlay = (ImageView) item.findViewById(R.id.imageViewPlay); imageViewPlay.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { // 事件统计 Map<String, String> map = new HashMap<String, String>(); map.put("group", paintingCategory.getName()); map.put("painting", painting.getName()); MobclickAgent.onEvent(context, "painting_sound", map); mediaPlayer.play(context, painting.getSoundPath()); } }); return item; }
@Override public int getCount() { return paintingCategory.count(); }