Code example for SparseArray

Methods: append

0
  private Drawable backgroundImage;
 
  public class TileSet { 
    private SparseArray<Bitmap> tileset;
    TileSet() { tileset = new SparseArray<Bitmap>(); }
    public void add(char c, Bitmap b) { tileset.append((int) c, b); }
    public Bitmap get(char c) { return tileset.get((int) c); }
  } 
 
  public TileView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TileView);
    tileWidth = tileHeight = tileSize = a.getInt(R.styleable.TileView_tileSize, 12);
    a.recycle();
    tileset = new TileSet();
    backgroundImage = null;
  } 
 
  public TileView(Context context, AttributeSet attrs) {
    this(context, attrs, 0);
  }