Draw a Circle when the user touches the screen

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Draw a Circle when the user touches the screen

Postby patrick91 » Sat Aug 01, 2009 6:08 pm

Hi, I've this code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. package com.patrick.games.whackgroundhog;
  3.  
  4.  
  5.  
  6. import android.app.Activity;
  7.  
  8. import android.content.Context;
  9.  
  10. import android.graphics.Canvas;
  11.  
  12. import android.graphics.Color;
  13.  
  14. import android.graphics.Paint;
  15.  
  16. import android.os.Bundle;
  17.  
  18. import android.view.MotionEvent;
  19.  
  20. import android.view.View;
  21.  
  22.  
  23.  
  24. public class Game extends Activity {
  25.  
  26.     /** Called when the activity is first created. */
  27.  
  28.     @Override
  29.  
  30.     public void onCreate(Bundle savedInstanceState) {
  31.  
  32.         super.onCreate(savedInstanceState);
  33.  
  34.         setContentView(new Ground(this));
  35.  
  36.     }
  37.  
  38.    
  39.  
  40.     class Ground extends View {
  41.  
  42.        
  43.  
  44.                 public Ground(Context context) {
  45.  
  46.                         super(context);
  47.  
  48.                 }
  49.  
  50.  
  51.  
  52.                 public void onDraw(Canvas canvas) {
  53.  
  54.                         canvas.drawColor(Color.BLACK);
  55.  
  56.                        
  57.  
  58.                 }
  59.  
  60.                
  61.  
  62.                 @Override
  63.  
  64.                 public boolean onTouchEvent(MotionEvent event) {
  65.  
  66.            
  67.  
  68.                         if (event.getAction() == MotionEvent.ACTION_DOWN) {
  69.  
  70.                                 //TODO: draw the circle
  71.  
  72.                         }
  73.  
  74.                         return true;
  75.  
  76.                 }
  77.  
  78.                
  79.  
  80.     }
  81.  
  82. }
  83.  
  84.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4


And I want to draw a circle when the onTouchEvent is called but I don't know how to get the canvas :(

Can you help me?

thanks :)
patrick91
Freshman
Freshman
 
Posts: 5
Joined: Thu Jul 02, 2009 8:58 am

Top

Try this

Postby hareesh » Sat Oct 31, 2009 12:01 am

Hareesh.
hareesh
Freshman
Freshman
 
Posts: 2
Joined: Fri Oct 30, 2009 11:57 pm
Location: San Diego

Postby chris_uk_83 » Sat Oct 31, 2009 5:17 pm

chris_uk_83
Freshman
Freshman
 
Posts: 5
Joined: Sat Oct 31, 2009 4:34 pm

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests