Search code examples
androidtextviewmarquee

Refreshing Marquee Text on Android


On launch, my marquee text is working normally. Then i want to update text in somewhen. I get text on internet and set it to textview:

marqueeText.setText(Html.fromHtml(GetNew.getNews()));

There is no problem about getting text from internet. But then the text is not sliding. What is the problem about that? Thanks for your help.

Edit: I get this log when try to refresh it. I refresh it in a thread.

06-12 10:25:04.403: E/tag(498): Only the original thread that created a view hierarchy can touch its views.

Solution

  • You should use the handler for working on UI thread.

    private Handler handler = new Handler(new Callback() {
    
            public boolean handleMessage(Message msg) {
                marqueeText.setText(Html.fromHtml(GetNew.getNews()));
                marqueeText.setSelected(true);
                marqueeText.setEllipsize(TruncateAt.MARQUEE);
                return false;
            }
        });
    

    And when you want to update the text in thread then use handler.sendEmptyMessage(0);