Okay, I'm trying to create a simple app that will draw a shape (I'm trying a circle) wherever you click. I have tried a couple times, but haven't gotten anything to work yet. I would think that somebody has done this before, so if theres a link to a tutorial/source code of a similar project, that would help. What I think I'm stuck on is how to use threads, and how to update the onDraw() function. If you haven't figured it out already, I'm pretty new to Android and even java.
Currently I have:
--Main.java--
public class MAIN extends Activity {
CustomDrawableView mCustomDrawableView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mCustomDrawableView = new CustomDrawableView(this);
setContentView(mCustomDrawableView);
}
//Implement a thread here that would somehow update the view everytime. Everytime I try this though it doesn't work
}
--CustomDrawableView.java--
public class CustomDrawableView extends View {
//private ShapeDrawable mDrawable;
int x=0;
int y=0;
public CustomDrawableView(Context context) {
super(context);
}
protected void onDraw(Canvas canvas) {
Paint mPaint = new Paint();
mPaint.setColor(0xffff0000);
canvas.drawCircle(x, y, 5, mPaint);
}
}
You don't need to explicitly create a thread for something this simple.
In your View, simply override onTouchEvent, switch on the MotionEvent.getAction, when it's ACTION_DOWN, set the x and y to MotionEvent.getX() and getY(), and call invalidate()