TextView.setText doesn't update

by Midian » Tue, 14 Apr 2009 13:04:40 GMT


Sponsored Links
 I have a Timer set up to update a TextView field once every second.
Thing is, I can't see any changes on screen!

Debugging shows...
setText inside the timer function *is* being called.
getText called on the text view returns the *correct* (new) text that
just isn't displayed!

I've tried TextView.postInvalidate() to no effect.
Code below.

Anyone seen this before?
Thanks.

----------------------------------------------------------------------------------------
IN MyActivity.onCreate:
        mMyTextView = (TextView)this.findViewById
(R.id.txtcurloctitle);

FROM MyTimerTask.Run
        String timeSinceUpdate = tracker.getUpdateAge();
        mMyTextView .setText("Current location (" + timeSinceUpdate +
"):");

IN MyActivity.onOptionsItemSelected:
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Debug");
        msg.setMessage(mMyTextView.getText());
        msg.setPositiveButton("OK", null);
        msg.show();

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



TextView.setText doesn't update

by Peter Carpenter » Wed, 15 Apr 2009 02:05:53 GMT


 Hi,

I'm not sure which thread timers fire in, but have you tried calling the
setText explicitly from the UI thread?

final String timeSinceUpdate = tracker.getUpdateAge();
runOnUiThread(new Runnable()
{
    public void run()
    {
        mMyTextView .setText("Current location (" + timeSinceUpdate +
")";
    }
}

Peter.

-----Original Message-----
From: android-developers@googlegroups.com
[mailto:android-develop...@googlegroups.com] On Behalf Of Midian
Sent: Tuesday, 14 April 2009 9:44 AM
To: Android Developers
Subject: [android-developers] TextView.setText doesn't update


I have a Timer set up to update a TextView field once every second.
Thing is, I can't see any changes on screen!

Debugging shows...
setText inside the timer function *is* being called.
getText called on the text view returns the *correct* (new) text that
just isn't displayed!

I've tried TextView.postInvalidate() to no effect.
Code below.

Anyone seen this before?
Thanks.

------------------------------------------------------------------------
----------------
IN MyActivity.onCreate:
        mMyTextView = (TextView)this.findViewById
(R.id.txtcurloctitle);

FROM MyTimerTask.Run
        String timeSinceUpdate = tracker.getUpdateAge();
        mMyTextView .setText("Current location (" + timeSinceUpdate +
"):");

IN MyActivity.onOptionsItemSelected:
        AlertDialog.Builder msg = new AlertDialog.Builder(this);
        msg.setTitle("Debug");
        msg.setMessage(mMyTextView.getText());
        msg.setPositiveButton("OK", null);
        msg.show();




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


Sponsored Links


Other Threads

1. Help in preferences - best practice?

Some of my app's preferences could use some more explanation than the
scarce space available for the summary. Sadly, there doesn't seem to
be support from the system, like an optional help button that shows a
longer text.
How do you solve this problem? The first thing that comes to mind is
an addional custom "preference" like "more information to above entry"
that opens an AlertDialog with the help text, but that's not really
nice for both user (two entries for the same preference) and the
developer (manual work to do in the PreferenceActivity). A bit nicer
for the user, but way more work for the developer would be custom
dialogs for each preference with more text and/or a help button.
Is there a better solution or even an officially recommended best
practice?

-- 

2. mediaController in APIDemo

Hi
I am using the code of APIDemo for streaming video.

I want to add control bar to the videoview.

I added the following code to the MediaPlayerDemo_Video.oncreate but
the control was not shown:

mPreview = (VideoView) findViewById(R.id.surface);
        MediaController mediaController = new
MediaController(mPreview.getContext());
                mediaController.setAnchorView(mPreview);
                mediaController.setMediaPlayer(mPreview);
                mPreview.setMediaController(mediaController);

any idea why?
thanks

Zohar

-- 

3. Need to get videoframes on android

4. limit the number of image to one for each swipe in android gallery

5. How to start an activity from a service

6. Android 3.0 64-bit system host required?

7. The ultimate, killer Android Marketplace replacement