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 :

mTextView.append(mText);
mScrollView.pageScroll(ScrollView.FOCUS_DOWN);

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?

Thanks.

--~--~---------~--~----~------------~-------~--~----~



How update TextView?

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


 Up!

2009/9/5 Francesco Pace <paxa...@gmail.com>


--~--~---------~--~----~------------~-------~--~----~


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:

mTextView.append("\n");
mTextView.append(mText);

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

mTextView.setText(mText);

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:

mScrollView.post(new Runnable() {
        public void run() {
                mScrollView.fullScroll(ScrollView.FOCUS_DOWN);
        }
});



--~--~---------~--~----~------------~-------~--~----~



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);

                    mScroll.post(new Runnable() {
                            public void run() {
                                mScroll.fullScroll(ScrollView.FOCUS_DOWN);
                            }
                    });
                }
            }
        };
       mButton.setOnClickListener(mStartListener2);

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?

Thanks,
Francesco



2009/9/6 Lance Nanek <lna...@gmail.com>



--~--~---------~--~----~------------~-------~--~----~



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
David






--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Android SDK and Helios - compatibility problems?

Are folks having success with Helios (Eclipse 3.6) and the latest SDK
(r_06)?

I am having problems getting the Eclipse DDMS to work;. It is missing
most of its views (such as logcat) and complained about that the first
time I ran it (but not since, so I don't have a list of what is going
on.

I had a previous working version with a prior Eclipse, but started
from scratch with this one. The steps were:

*Download and install (via unzip) Helios

*Download and unzip files for SDK

*Run SDK setup and download everything it would download.
**It complained that some packages available were incompatible and it
wouldn't download (or list) them

*Install the Eclipse plug-in from https://dl-ssl.google.com/android/eclipse/
using the Eclipse new software dialog

Is Helios incompatible? Or am I doing something wrong?

Thanks

-- 

2. why is there no android tablet nearly as good as ipad?

imo, it is those cheap crappy hardware that are poisoning non-mobile-
phone android market. few weeks ago i bought one and returned it on
the same day as it was delivered; compared with ipad, it is a crap.
luckily i got full refund from the seller. thank god~

On Jun 27, 6:36pm, Michael MacDonald <googlec...@antlersoft.com>





-- 

3. Track user location.

4. UltimateFave

5. Implementing a toolbar/taskbar kind of thing.

6. why is there no android tablet nearly as good as ipad?

7. Diapad phone red button press