title: Drawing a GridView on a Canvas in Android
body: <p>I am trying to draw a GridView on a Canvas in an Android app as follows, but nothing is displayed on screen.</p>
  
  <pre><code>            int width = 400;
      int height = 400;
  
              private String[] numbers = {"1", "2", "3", "4", "5", "6"};
      Bitmap bitmap = Bitmap.createBitmap(width, height, Config.RGB_565);     
  
      Canvas canvas = new Canvas(bitmap);
  
      canvas.drawColor(Color.YELLOW);
  
      GridView gridview = new GridView(MainActivity.this);
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this, Android.R.layout.simple_list_item_1, numbers);
      gridview.setAdapter(adapter);
  
      LinearLayout layout = new LinearLayout(MainActivity.this);
  
  
      layout.addView(gridview);
  
      layout.measure(canvas.getWidth(), canvas.getHeight());
      layout.layout(0, 0, canvas.getWidth(), canvas.getHeight());
  
      layout.draw(canvas);
  
      ImageView imageView = (ImageView) findViewById(R.id.imageView1);
  
      imageView.setImageBitmap(bitmap);
  </code></pre>
  
  <p>Can anyone please suggest what's wrong here?</p>
  
  <p>Thanks.
  James</p>