Rud wrote:
> The is (maybe) a simple Java question but I can't find the anwer
> searching.
> 
> The code is:
> 
>         final Formatter f = new Formatter();
> 
>         for (Sentinel s : Sentinel.mSentinels) {
>             if (s.mIsLive) {
>                 pos++;
>                 f.format("%4d%5d", s.mPos.x, s.mPos.y);
>                 canvas.drawText(f.toString(), x_pos, (pos *
> mHalfHeight), mPaint);
>             }
> 
> The problem is Formatter appends the output rather than clearing the
> underlying buffer for each 'format'. Okay, my bad. I looked for
> something to clear the underlying buffer but can't find anything.
> 
> Suggestions?

Create a new Formatter.

If you look at the constructors for Formatter, you will see that its
mission in life is to dump data to some stream-like object, be that a
literal stream, or a File, or any sort of Appendable object. As such, it
 is aimed at calling format() multiple times to dump more data to the
same output stream, then closing up the stream (via flush() and close()).

If you want to dump data to some new stream (in your case, a new
String), you need to create a new Formatter.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Android App Developer Books: http://commonsware.com/books.html

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to