Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Drawing Multiple Circles without the old ones disappearing

 
Zhiming Shi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


coordsWalked.pkm is a text file that has a series of coordinates separated by a splitter so that *2 - 1 is the x coordinate and *2 - 0 is the y coordinate. No need to worry about this too much, all of my circles are being drawn at exactly the correct coordinates, and thus in the correct place. The problem is that it only draws a circle at the last coordinate in the text file. What I want is for it to draw circles for every single one of the coordinates in the file and show them at the same time, but instead it only ever shows the last circle. I tried to solve this using the for(Point p: points) solution I found online, but it still runs exactly the same as before. I've also tried tweaking the invalidates, turning them off and on etc, but it makes no apparent difference.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Zhiming Shi wrote:

You only have one point, which you reuse, changing its location over and over again. If you need multiple points, then you need to make multiple Point instances, not re-use the same one.

Also, you should not be reading the file in during the onDraw() method. If the file doesn't change while the application is running then the file should be read in the MyView constructor and the points stored for later use. If the file does change then you should have a separate utility for detecting the changes and modifying the list. Reading from a file can be slow, and can slow down your UI. It can lead to poor performance and hangs. So it should never be done in the UI thread.
 
Zhiming Shi
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good advice!

I got rid of the points thing.
Also, I created a different class and made it so that the draw method loads a bitmap and every time a coordinate is added it goes to the new class and saves it directly to the bitmap so that I wouldn't have a bulky text file full of coordinates. This improved the performance quite a bit.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic