title: Draw multiple shapes using loop - Android Canvas
body: <p>I am very new to android development and have been trying to draw a square comprised of multiple smaller rectangles of different colours... Like a Mosaic essentially. </p>
  
  <p>Basically at the moment I am reading values from a file which assigns the colour to the smaller Rects. I am using a pair of nested for loops to try to draw the small Rects sequentially, line by line. However when the program finishes there is only one small Rect drawn which is the last one to be drawn and its colour corresponds to the first value read from the file.</p>
  
  <p>Here is some of my code to show you what I mean:</p>
  
  <pre><code>public SnapshotDraw(Context context) {
      super(context);
  
      for(int a = 0; a &lt; 63; a++){
          for(int b = 0; b &lt; 63; b++){
              fileName = PREFIX + "2" + EXTENSION;
  
              try {
                  bf = new BufferedReader(new FileReader(fileName));
                  tokens = new StringTokenizer(bf.readLine(), " \n");
                  weight = Byte.parseByte(tokens.nextToken());
  
                  x_scalar = b*MAG;
                  y_scalar = a*MAG;   
  
                  mDrawable = new ShapeDrawable(new RectShape());
                  mDrawable.getPaint().setColor(colour.getColour(weight));
                  mDrawable.setBounds((X_OFFSET + x_scalar), (Y_OFFSET + y_scalar), ((MAG + X_OFFSET) + x_scalar), ((MAG + Y_OFFSET) + y_scalar));
  
              } catch (FileNotFoundException ex) {
                  Logger.getLogger(NetworkUtilities.class.getName()).log(Level.SEVERE, null, ex);
              } catch (IOException ex) {
                  Logger.getLogger(NetworkUtilities.class.getName()).log(Level.SEVERE, null, ex);
              }
          }
      }
  }
  
  protected void onDraw(Canvas canvas) {
      mDrawable.draw(canvas);
  }
  </code></pre>
  
  <p>This except is from a class which extends View and is called inside an <code>onCreate()</code> method in an Activity.</p>
  
  <p>I would appreciate any guidance in this and thanks in advance!!</p>
  
  <p>Cheers.</p>