コード例 #1
0
  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    ViewHolder vholder;
    View v = convertView;

    if (categories.size() > 0) {
      if (v == null) {
        v = inflater.inflate(R.layout.grid_row, parent, false);
        vholder = new ViewHolder();
        vholder.image = (ImageView) v.findViewById(R.id.imageView);
        vholder.text = (TextView) v.findViewById(R.id.textView);
        v.setTag(vholder);
      } else {
        vholder = (ViewHolder) v.getTag();
      }

      if (categories.get(position).getLogo() != null)
        vholder.image.setImageBitmap(
            BitmapFactory.decodeByteArray(
                categories.get(position).getLogo(), 0, categories.get(position).getLogo().length));
      else {
        Drawable myIcon = activity.getResources().getDrawable(R.drawable.category_effect);
        if (android.os.Build.VERSION.SDK_INT >= 16) vholder.image.setBackground(myIcon);
        else vholder.image.setBackgroundDrawable(myIcon);
      }

      vholder.text.setText(categories.get(position).getName());

      v.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {

              Intent intent = new Intent(activity, Apps.class);
              intent.putExtra(CATEGORY, categories.get(position).getName());

              ActivityOptionsCompat options =
                  ActivityOptionsCompat.makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight());
              ActivityCompat.startActivity(activity, intent, options.toBundle());
            }
          });
    }
    return v;
  }