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);
tv.setText("Starting.");
setContentView(tv);

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

tv.setText("Working...");

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?

Cheers,
Tom.

--



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
 http://sites.google.com/site/rezmobileapps/treking 

--


Sponsored Links


Other Threads

1. BUG of IMF

Although the IMF has provided EditorInfo to get  the attributes of
components with focus.
However, the attributes is not fully.

First of all, we could not distinguish between Button and EditText
components, they have the same  InputType  value
"EditorInfo.TYPE_CLASS_TEXT"

Secondly,after the EditText was been setEditable (false), it should
not be editeable, but through the input method, you can still enter
text, because IMF still  get a  InputConnection associated with that
EditText.


----------------------------------------------------------------------------------------------------------------------
IMFditorInfo€€€ButtonditTextinputTypeutton
ditTextetEditable(false)€MFInputConnection€--~--~---------~--~----~------------~-------~--~----~

2. What's in raw data from PictureCallback of camera?

Hi,
Our university is intending to use the Android as a platform for
mobile image analysis. We're wondering what kind of information is
returned in the raw format when android.hardware.Camera.takePicture()
is called with a raw Camera.PictureCallback. I can't seem to find more
information about it on the 
http://code.google.com/android/reference/android/hardware/Camera.PictureCallback.html
page.

Thanks,
Xiao

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

3. Comments/Ratings need to expire!

4. Android toolchain

5. How to create a "Hello World" application?

6. SyncML in android

7. How is tabbed navigation done on http://developer.android.com/community/index.html