title: Drawing a line with canvas from an Activity
body: <p>I have read the following links:</p>
  
  <p><a href="https://stackoverflow.com/questions/3616676/how-to-draw-a-line-in-android/12987068#12987068">How to draw a line in android</a></p>
  
  <p><a href="http://marakana.com/s/android_2d_graphics_example,1036/index.html" rel="nofollow noreferrer">http://marakana.com/s/android_2d_graphics_example,1036/index.html</a></p>
  
  <p><a href="http://developer.android.com/reference/android/graphics/Canvas.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/graphics/Canvas.html</a></p>
  
  <p><a href="https://stackoverflow.com/questions/6572905/activity-setcontentview-view-setcontentview">Activity.setContentView, View.setContentView?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/11147704/how-to-create-an-activity-without-setcontentviewr-layout-main">How to create an activity without &#39;setContentView(R.layout.main)&#39;</a></p>
  
  <p><a href="http://www.jayway.com/2009/03/26/layout-resources-in-android/" rel="nofollow noreferrer">http://www.jayway.com/2009/03/26/layout-resources-in-android/</a></p>
  
  <p>I have read the previous articles that talk about about my problem but I can't solve my problem.</p>
  
  <p>My problem is that I want to draw straight lines to simulate the connection between images, but basically is to paint straight lines.</p>
  
  <p>All the examples I've seen have the main class that inherits from the activity and have another inner class that inherits from the View. And in the main class set the user interface that contains the View class, so we have a empty user interface.
  Something like this:</p>
  
  <pre><code>public class ActivityMain extends Activity{
  
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      MyView view1 =new MyView(this);
      setContentView(view1);       
  }
  
  public class MyView extends View {
      public MyView(Context c) {
          super(c);
      }
  }
  //And more code
  }
  </code></pre>
  
  <p>I want to set my user interface (xml file) in the class that inherits from the activity (as usual):</p>
  
  <pre><code>public class ActivityMain extends Activity{
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.union);
  }
  }
  </code></pre>
  
  <p>And I want from the class that inherits from activity to draw straight lines, I don't want to have any class that inherits from View.</p>
  
  <p>I tried the following but I don't see any line:</p>
  
  <pre><code>public boolean onTouchEvent(MotionEvent event) {
  int x = (int) event.getX();
  int y = (int) event.getY();
  
  switch(event.getAction()) {
      case MotionEvent.ACTION_DOWN:
          Canvas canvas = new Canvas();
          Paint paint = new Paint();
                      paint.setColor(Color.BLACK);
          canvas.drawLine(0, 0, 300, 700, paint);     
      break;
      case MotionEvent.ACTION_MOVE:
      break;
      case MotionEvent.ACTION_UP:
      break;
  }   
  return true;
  }
  </code></pre>
  
  <p>In the previous method I want to draw a line from the corner 0,0 to the corner 300,700. It's a simple test. But I don't draw anything and I don't know why.</p>