Refreshing Marquee Text on Android

♀尐吖头ヾ 提交于 2019-12-24 17:52:40

问题


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.

回答1:


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




回答2:


i think u have not added in activity

 marqueeText.setSelected(true);



回答3:


The marquee on TextView will only scroll if the TextView is either in the selected or focused state

try TextView.setEnabled(true) or TextView.requestFocus() or TextView.setSelected(true);




回答4:


You cannot update view from threads other than the UI thread.



来源:https://stackoverflow.com/questions/10994900/refreshing-marquee-text-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!