creating another copy of a xml shape in android during runtime
<p>I'm trying to create an application that has a "palette" with different basic shapes (e.g. circle, rectangle etc) and the user can drag and drop copies of these onto a canvas. My shapes are defined in xml files. At the moment I can move them onto the canvas but then they disappear from the palette(as I'm moving the original view), so I'd need a way to create a new copy of the shapes when the user clicks on one and drags it to the canvas. I've tried searching for solutions and I looked into LayoutInflaters but couldn't get them to work. Are LayoutInflaters the way to go or is there a better solution? 
Please see my code snippet below.</p>

<p>Thanks</p>

<p>in my onDrag() :</p>

<pre><code>    case DragEvent.ACTION_DROP:
    // Dropped, reassign View to ViewGroup
    View view = (View) event.getLocalState();
    ViewGroup owner = (ViewGroup) view.getParent();
    //owner.removeView(view);
    LinearLayout container = (LinearLayout) v;
    View copyview = getLayoutInflater().inflate(R.drawable.rectangle, null);
    container.addView(copyview);
    copyview.setVisibility(View.VISIBLE);
    break;
</code></pre>

<p>EDIT:</p>

<p>XML for rectangle:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" &gt;

    &lt;stroke
        android:width="2dp"
        android:color="#FFFFFFFF" /&gt;

    &lt;solid android:color="#ffff00ff" /&gt;

&lt;/shape&gt; 
</code></pre>

<p>logcat:</p>

<pre><code>10-18 19:59:12.461: I/dalvikvm(830): threadid=3: reacting to signal 3
10-18 19:59:12.741: I/dalvikvm(830): Wrote stack traces to '/data/anr/traces.txt'
10-18 19:59:12.961: I/dalvikvm(830): threadid=3: reacting to signal 3
10-18 19:59:13.101: I/dalvikvm(830): Wrote stack traces to '/data/anr/traces.txt'
10-18 19:59:13.372: D/android.widget.GridLayout(830): vertical constraints: y1 - y0 &gt; 160, y2 - y1 &gt; 1038, y2 - y0 &lt; 1038 are inconsistent; permanently removing: y2 - y0 &lt; 1038. 
10-18 19:59:13.481: I/dalvikvm(830): threadid=3: reacting to signal 3
10-18 19:59:13.542: I/dalvikvm(830): Wrote stack traces to '/data/anr/traces.txt'
10-18 19:59:13.661: D/gralloc_goldfish(830): Emulator without GPU emulation detected.
10-18 19:59:15.531: D/AndroidRuntime(830): Shutting down VM
10-18 19:59:15.531: W/dalvikvm(830): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
10-18 19:59:15.631: E/AndroidRuntime(830): FATAL EXCEPTION: main
10-18 19:59:15.631: E/AndroidRuntime(830): android.view.InflateException: Binary XML file line #2: Error inflating class shape
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:691)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-18 19:59:15.631: E/AndroidRuntime(830):  at com.neonwizard.shapes.DragActivity$MyDragListener.onDrag(DragActivity.java:68)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.View.dispatchDragEvent(View.java:13461)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1155)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1141)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1141)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1141)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1141)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewRootImpl.handleDragEvent(ViewRootImpl.java:3471)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2620)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.os.Looper.loop(Looper.java:137)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.app.ActivityThread.main(ActivityThread.java:4424)
10-18 19:59:15.631: E/AndroidRuntime(830):  at java.lang.reflect.Method.invokeNative(Native Method)
10-18 19:59:15.631: E/AndroidRuntime(830):  at java.lang.reflect.Method.invoke(Method.java:511)
10-18 19:59:15.631: E/AndroidRuntime(830):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
10-18 19:59:15.631: E/AndroidRuntime(830):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
10-18 19:59:15.631: E/AndroidRuntime(830):  at dalvik.system.NativeStart.main(Native Method)
10-18 19:59:15.631: E/AndroidRuntime(830): Caused by: java.lang.ClassNotFoundException: android.view.shape
10-18 19:59:15.631: E/AndroidRuntime(830):  at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
10-18 19:59:15.631: E/AndroidRuntime(830):  at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
10-18 19:59:15.631: E/AndroidRuntime(830):  at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.createView(LayoutInflater.java:552)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:636)
10-18 19:59:15.631: E/AndroidRuntime(830):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
10-18 19:59:15.631: E/AndroidRuntime(830):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
10-18 19:59:15.631: E/AndroidRuntime(830):  ... 20 more
10-18 19:59:16.251: I/dalvikvm(830): threadid=3: reacting to signal 3
10-18 19:59:16.282: I/dalvikvm(830): Wrote stack traces to '/data/anr/traces.txt'
</code></pre>
