Text inside a dragable cirlce in android
<p>well I'm trying to create an Android application where the user can drag any circle over the other and the textbox should show the sum of those two circles. Every time the programs starts it should show circles with random position and random number from 1 -9.</p>

<p>Unfortunately I am no where near that goal I have created one circle but when i try to drag it the application crashes. Please also help me with the rest of the functionality of the app. thanks.</p>

<p>The final output should look something like this:
<img src="http://i.stack.imgur.com/9zJ18.png" alt="enter image description here"></p>

<p><strong>MainActivity.java</strong></p>

<pre><code>package com.dragandadd;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FrameLayout main = (FrameLayout) findViewById(R.id.activity_main);
        main.addView(new Ball(this,50,50,25));

        main.addView(new Ball(this,50,50,25));

        main.setOnTouchListener(new View.OnTouchListener() {
            public boolean onTouch(View v, MotionEvent e) {
                float x = e.getX();
            float y = e.getY();
                FrameLayout flView = (FrameLayout) v;
            flView.addView(new Ball(getParent(), x,y,25));
            return true;
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
</code></pre>

<p><strong>Ball.java</strong></p>

<pre><code>package com.dragandadd;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

public class Ball extends View {
    final float x;
    final float y;
    final int r;
    final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    public Ball(Context context, float x, float y, int r) {
        super(context);
        mPaint.setColor(0xFFFF0000);
        this.x = x;
        this.y = y;
        this.r = r;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawCircle(x, y, r, mPaint);
    }
}
</code></pre>

<p><strong>activity_main</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#FF66FF33" /&gt;
</code></pre>
