Android runOnUiThread不更新UI元素 [英] Android runOnUiThread not updating UI elements
本文介绍了Android runOnUiThread不更新UI元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发使用网格视图的android应用程序。我想动态更新网格项目。我的网格项目包含一个标题文本。我试图这样做,但它对我不起作用。
Hi I am developing android application in which I am using grid view. I want to updated grid item dynamically.My grid item contains one title text. I tried to do it like this but it is not working for me.
((Activity)context).runOnUiThread(new Runnable()
{
public void run()
{
Debug.print("this is update progress inside thread ...");
owner.setText("Uploading...");
invalidate();
requestLayout();
}
});
因此在上面的代码中是其打印调试语句。但是不更新网格项内的所有者文本。
So in above code its printing debug statement. But not updating my owner text which is inside grid item.
我也尝试过此操作...
I tried this also...
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
owner.setText("Uploading...");
}
};
handler.sendEmptyMessage(0);
推荐答案
runOnUiThread(new Runnable() {
@Override
public void run() {
Debug.print("Updating UI ...");
owner.setText("Uploading ...");
invalidate();
requestLayout();
}
});
这篇关于Android runOnUiThread不更新UI元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文