android - ArrayList elements changed to last entry every time -
i have class such below . when run , should save x , y touched on screen positions making circles in circles arraylist every time touch . @ every time elements of array list have been last x,y ( elements changed last element) . should ?
package com.siamak.rain.ball; import java.util.arraylist; import android.content.context; import android.graphics.canvas; import android.graphics.color; import android.graphics.paint; import android.graphics.paint.style; import android.util.attributeset; import android.view.motionevent; import android.widget.imageview; public class balls extends imageview { static arraylist<circle> circles = new arraylist<circle>(); static paint cp; public balls(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); initial(); } public balls(context context, attributeset attrs) { super(context, attrs); initial(); } public balls(context context) { super(context); initial(); } public static class circle { static float x; static float y; } public static void initial() { cp = new paint(); cp.setcolor(color.green); cp.setantialias(true); cp.setstyle(style.stroke); cp.setstrokewidth(5); } @override public boolean ontouchevent(motionevent event) { super.ontouchevent(event); switch (event.getaction()) { case (motionevent.action_down): circle c = new circle(); c.x = event.getx(); c.y = event.gety(); circles.add(c); invalidate(); break; } return true; } @override protected void ondraw(canvas canvas) { // todo auto-generated method stub super.ondraw(canvas); (circle c: circles) canvas.drawcircle(c.x, c.y, 50, cp); } }
Comments
Post a Comment