title: How to dynamically create a large number of imageView in Android
body: <p>Hello I am making a jigsaw puzzle application and for that i have 16 made smaller bitmaps out of a large scaled bitmap with height = width = 240. Now I have to dynamically display these bitmaps in a single activity at one time. The code I tried is not working properly as it is displaying all images in a single row and size of image is too small. Here is the code:</p>
  
  <pre><code>public void display()
      {
          float x =0;
          float y = 0;
          LinearLayout llMain = new LinearLayout(this);
          for(int i=0;i&lt;3;i++)
          {
              LinearLayout llRow = new LinearLayout(this);
              for(int j=0;j&lt;tiles.length/4;j++)
              {
                  ImageView iv = new ImageView(this);
                  iv.setImageBitmap(tiles[j]);// get bitmap from image path
                  iv.setX(x);
                  iv.setY(y);
                  x = y = x + 60;
                  llRow.addView(iv);
              }
              llMain.addView(llRow);
          }
          setContentView(llMain);
         }
  }
  </code></pre>
  
  <p>Here is the LogCat:</p>
  
  <pre><code>01-05 00:32:35.820: D/dalvikvm(11346): GC_EXTERNAL_ALLOC freed 47K, 52% free 2599K/5379K, external 1990K/2108K, paused 135ms
  01-05 00:32:44.183: D/dalvikvm(11346): GC_EXTERNAL_ALLOC freed 43K, 50% free 2739K/5379K, external 2477K/2527K, paused 18ms
  01-05 00:32:45.156: I/dalvikvm(11346): Could not find method android.widget.ImageView.setX, referenced from method com.maju.jigsawpuzzle.PlayBoard.display
  01-05 00:32:45.156: W/dalvikvm(11346): VFY: unable to resolve virtual method 3236: Landroid/widget/ImageView;.setX (F)V
  01-05 00:32:45.156: D/dalvikvm(11346): VFY: replacing opcode 0x6e at 0x002e
  01-05 00:32:45.156: D/dalvikvm(11346): VFY: dead code 0x0031-003e in Lcom/maju/jigsawpuzzle/PlayBoard;.display ()V
  01-05 00:32:45.179: D/AndroidRuntime(11346): Shutting down VM
  01-05 00:32:45.179: W/dalvikvm(11346): threadid=1: thread exiting with uncaught exception (group=0x40015578)
  01-05 00:32:45.187: E/AndroidRuntime(11346): FATAL EXCEPTION: main
  01-05 00:32:45.187: E/AndroidRuntime(11346): java.lang.NoSuchMethodError: android.widget.ImageView.setX
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at com.maju.jigsawpuzzle.PlayBoard.display(PlayBoard.java:164)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at com.maju.jigsawpuzzle.PlayBoard.shuffleArray(PlayBoard.java:143)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at com.maju.jigsawpuzzle.PlayBoard.breakImage(PlayBoard.java:123)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at com.maju.jigsawpuzzle.PlayBoard.onCreate(PlayBoard.java:40)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.os.Looper.loop(Looper.java:123)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at android.app.ActivityThread.main(ActivityThread.java:3687)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at java.lang.reflect.Method.invoke(Method.java:507)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
  01-05 00:32:45.187: E/AndroidRuntime(11346):    at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>Line 164 is the line:</p>
  
  <p>iv.setX(x);</p>
  
  <p>Does anybody know the solution? Moreover I have to register onClick with them...</p>
  
  <p>Thanks in advancce</p>