#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    30
    Rep Power
    1

    Question Help! Create an Object of a line drawn and add it to ArrayList


    I can draw a line using the ontouch method and the rubber-band thingy works, but how would I make the drawn line into an object and add it to my ArrayList? Also, I'm gonna need to apply that to two more shape types(Circle, and Rectangle)

    My code for onTouchEvent(So I can take the line that I draw, make an object of it, then store it in my arraylist called shapeArray.

    Code:
    public boolean onTouchEvent(MotionEvent event)
    	{
    		// get the current X and Y position from the event
    		currentX = event.getX();
    	    currentY = event.getY();
    	    
    	    // switch on the touch event action
    		switch(event.getAction())
    		{
    		case MotionEvent.ACTION_DOWN:
    			
    			// start the line
    			startX = currentX;
    			startY = currentY;
    			invalidate();
    			return true;
    		case MotionEvent.ACTION_UP:
    			
    // this is what should be storing drawn lines as objects in an Arraylist.
        MyLine aline = new MyLine(startX, startY, currentX, currentY, color);
    			shapeArray.add(aline);
    			invalidate();
    			return true;
    		case MotionEvent.ACTION_MOVE:
    			deltaX = currentX - startX;
                deltaY  =  currentY - startY;
                invalidate();
    			return true;
    		default:
    			return super.onTouchEvent(event);
    		}
    	}
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    30
    Rep Power
    1
    Originally Posted by darthvader45
    I can draw a line using the ontouch method and the rubber-band thingy works, but how would I make the drawn line into an object and add it to my ArrayList? Also, I'm gonna need to apply that to two more shape types(Circle, and Rectangle)

    My code for onTouchEvent(So I can take the line that I draw, make an object of it, then store it in my arraylist called shapeArray.

    Code:
    public boolean onTouchEvent(MotionEvent event)
    	{
    		// get the current X and Y position from the event
    		currentX = event.getX();
    	    currentY = event.getY();
    	    
    	    // switch on the touch event action
    		switch(event.getAction())
    		{
    		case MotionEvent.ACTION_DOWN:
    			
    			// start the line
    			startX = currentX;
    			startY = currentY;
    			invalidate();
    			return true;
    		case MotionEvent.ACTION_UP:
    // this is what should be storing drawn lines as objects in my ArrayList.			
    MyLine aline = new MyLine(startX, startY, currentX, currentY, color);
    			shapeArray.add(aline);
    			invalidate();
    			return true;
    		case MotionEvent.ACTION_MOVE:
    			deltaX = currentX - startX;
                deltaY  =  currentY - startY;
                invalidate();
    			return true;
    		default:
    			return super.onTouchEvent(event);
    		}
    	}
    I'm a bit stuck on how to get this to work correctly.

IMN logo majestic logo threadwatch logo seochat tools logo