trying to get onTouch to work, please help!

Basic Tutorials concerning: GUI, Views, Activites, XML, Layouts, Intents, ...

trying to get onTouch to work, please help!

Postby mongrove » Fri Aug 06, 2010 2:00 pm

Hi, this is my first post on the board, Im looking forward to getting involved with anddev :)
Help would be very much appreciated.

I would like the code below simply to move the circle + 50 in the x axis:
Code: Select all
package com.android.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.graphics.*;
import android.content.Context;


public class Test extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        DrawableView dv = new DrawableView(this);
        setContentView(dv);
       
    }
   
    public class DrawableView extends View implements View.OnTouchListener{
       Context mContext;
       
       int x = 0;

       public DrawableView(Context context) {
          super(context);
          mContext = context;
         
       }
       
       protected void onDraw(Canvas canvas){
           Paint myPaint = new Paint();
           myPaint.setStrokeWidth(3);
           myPaint.setColor(0xFF097286);
           canvas.drawCircle(x, 200, 50, myPaint);
           invalidate();
       }

      @Override
      public boolean onTouch(View v, MotionEvent event) {
         // TODO Auto-generated method stub
         x +=50;
         return false;
      }
    }   
}
mongrove
Freshman
Freshman
 
Posts: 2
Joined: Fri Aug 06, 2010 1:25 pm

Top

Return to Novice Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests