问题
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