Very simple problem (probably)

by Tom3030 » Tue, 04 May 2010 03:06:31 GMT

Sponsored Links
 Hi All,

This is probably going to be extremely simplistic, but I have an
activity that does some work and is supposed to update the text view
to let the user know where the process is at (some sort of progress
indicator basically). But for some reason none of my textview updates
make it to the screen until the activity has basically completed, by
which time updates are pointless!

After the oncreate of the Activity class I have this ...

TextView tv = new TextView(this);

and then throughout the class at various points (at the moment just
one long procedure .... yeah I know ...) I have ...


etc. etc. but none of these appear while it's executing. I've tried
setting invalidate() but that doesn't seem to make it redraw. The
actual procedure itself runs fine (takes about 10-15 seconds). Do I
have to do some fancy threading to update the UI or what?



Very simple problem (probably)

by TreKing » Tue, 04 May 2010 03:17:44 GMT


Basically? Yup.

The gist of it is this: setText does just that - sets the text to be used on
the view - it doesn't actually do any drawing. That happens later on in the
main thread, after your onCreate call, so you can call setText as many times
as you want within a function, nothing but the last call will actually show
up during the next draw phase.

You will have to split out your loading code into a thread and post updates
to the main UI thread with the current progress. Or better yet, use an
AsyncTask - this is pretty much what it's for.

TreKing - Chicago transit tracking app for Android-powered devices 


Sponsored Links

Other Threads

1. Update for Android Marketplace....

Anyone with a pre-release unit is looking at a re-download for all their 
marketplace obtained apps;



2. For those who still think the "free" G1 in the UK is a bargain...

I've done some quick calculations based on the cheapest tariff available 
and it works out that in the UK the total cost for the first two years 
of ownership is WELL OVER DOUBLE that of buying the 'phone in the US 
(the UK cost is 215% of the US cost to be precise).

For those who think this is just because the UK is has rip off prices in 
general (a view I wouldn't entirely disagree with) , I've done a 
comparison with some of the other recent phones available in the UK on 
various carriers over 2 years on contract with free internet access;

iPhone 3G 16GB on O2 : G1 is 10% more expensive
Nokia N96 on Three : G1 is 15% more expensive
Blackberry Storm on Vodafone : G1 is 25% more expensive

So as you can see, the G1 REALLY isn't a bargain in the UK.


P.S. If anyone sees a fault in my calculations please speak up.

179 USD for the 'phone
25 USD x 24 months for the Tariff

Total : Total 779 USD

0 GBP for the 'phone
40 GBP x 24 months for the Tariff

Total: 960GBP (roughly 1,675 USD)

Al Sutton




4. APIDemo icon gone

5. My first attempt at writing an Android tutorial

6. dalvikvm: Ignoring not-yet-ready ... using slow path

7. Collecting opinions about Android for an article