title: Create Button on every touch on screen
body: <p>I want to make an application where whenever I touch the screen, which should be blank at the start, a button will be created and pop up onto the screen. So what I tried here is to make a button in main.xml and call it by id. Then I applied this method.</p>
  
  <pre><code>public class TouchButtonActivity extends Activity {
  Button b;
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      b=(Button) findViewById(R.id.b1);
      b.setOnTouchListener(nextListener);
  }
  
  
  public OnTouchListener nextListener = new OnTouchListener() {
      @Override
      public boolean onTouch(View v, MotionEvent event) {
          if (event.getAction() == MotionEvent.ACTION_DOWN) {
              float x = event.getX()*event.getXPrecision();
              float y = event.getY()*event.getYPrecision();
              FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
              p.gravity = Gravity.TOP;
              p.leftMargin = (int) x;
              p.topMargin = (int) y;
              b.setLayoutParams(p);
              return true;
          }
          return false;
      }
  };
  
  }
  </code></pre>
  
  <p>This my xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
   &gt;
  
  &lt;Button
      android:id="@+id/b1"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="B" /&gt;
  
  &lt;/FrameLayout&gt;
  </code></pre>
  
  <p>How could i do this?</p>