How update TextView?

by Francesco Pace » Sat, 05 Sep 2009 21:35:21 GMT

Sponsored Links
 Hi developers,
I have a question.
In my android application I have a TextView in a ScrollView.

I want to update TextView dinamically and I write this statement :


and so my application works.
Unfortunately the strings that I have to insert are shown ALL TOGETHER at
the end of application.
Can anyone help me?



How update TextView?

by Francesco Pace » Sun, 06 Sep 2009 03:59:48 GMT


2009/9/5 Francesco Pace <>


Sponsored Links

How update TextView?

by Lance Nanek » Sun, 06 Sep 2009 11:59:06 GMT

 Not sure exactly what problem you are seeing. If you want separation
between the things you append, then append some extra space or line
feeds like this:


If you want to replace the things that were previously in the
TextView, then use the setText method:


If you want the ScrollView to properly account for the things you just
added and go all the way down to the bottom then use this monstrosity: Runnable() {
        public void run() {


How update TextView?

by Francesco Pace » Sun, 06 Sep 2009 17:22:48 GMT

 Hello Lance,
Thanks for you answer. I try with you code but my program doesn't work
correctly. It show me strings but all together at the end of my activity.

For example, I have:

       View.OnClickListener mStartListener2 = new OnClickListener() {
            public void onClick(View v) {
                for(int i=0;i<1000;i++) {
                    mText.append("mytext " + i + "\n);

           Runnable() {
                            public void run() {

Then I start my application.
When I press mButton my program doesn't write strings "in real time" (mytext
1 , mytext 2, etc etc) but show me all at the end of activity.
Sorry for my english, I'm an italian student.
Can you help me?


2009/9/6 Lance Nanek <>


How update TextView?

by davidjspooner » Tue, 08 Sep 2009 09:39:40 GMT

 Assuming that is in the main thread then the runnable for display
updates and layout changes is not going to get a chance to run until
after your synchronous  loop exists. You need to either split your
logic up into chunks and use Handlers posted into the main ui thread
or move your logic into a worker thread ( where you will need to post
the updates back to the ui thread with a handler )

Basically read through the source for handlers and how the update and
layouts ui code works...

Hope that helps


Other Threads

1. How to increase FPS (now ~20, desired ~40-50)

Hi Andre,

you should definitely read the "Designing for Performance" document

I think you might speed up your onDraw() method a little bit this way,
though I think you might not reach more than 30 or 35 FPS.
At first you should eliminate all function calls in your onDraw()
method. I know this is bad code style, but it really is faster. I am
drawing some bitmaps for a project here this way.
Second, you should create local variables for all attributes you use
more than once.
Third and most importantly: Remove unnecessary code. For example, you
call System.currentTimeMillis() relatively often (I think you used
this code for performance measuring, but anyway).

And last but not least: Android comes with a profiler. Try to use
it. :-)


Marc Reichelt   ||

> }

2. no sound from music players even when alsa is fully functional


I am trying to get the music applications on android (Eclair) (Beagle)
to play mp3, the applications show that the song is being played but
there is no sound output, also we have installed aplay and we able to
play wav files, is there any changes required to get intergrate alsa
with android audio.

Rahul Soparkar


3. Problem while sending unicode character via SMS

4. Notification sound from file inside the app package ?

5. Timer and Timer Task

6. program's offline installation

7. adding voice search