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 check which button is clicked

hi friends,
I have 3 buttons on the screen and i have to perform different task
according to the button clicked ,how can i check which button is
Thanks in Advance

2. ListView issue- getchildat()

Hi All,

I m having  problem in setting soem items in list. getChildAt() returns null
if its not in the visible area :(, is there any workaround for this?

            for (int i = 1; i < getListView().getCount(); i++)
                mCheckBox =
                Flag = true;

Assume my list is having 8 items, it works fine for 6 items, but anything
more 6 is a fail.

Any help is appreciated...


3. Checking user activity / whether the screen is locked.

4. service dead cause ap gotten killed by system?

5. Problem with global variables

6. Install .odex + .apk

7. java.lang.VerifyError -- in Android