问题
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);
回答1:
Try to refresh your adapter which you used to load the grid item. Either you could use invalidateViews() method or adapter.notifyDataSetChanged()
This will help you to resolve your issue.
Happy coding..
回答2:
So in above code its printing debug statement. But not updating my owner text which is inside grid item.
I think it's textview does not reference to your item in grid adapter. You can check it by set tag when init and getTag() inside runonUIThread method.
Let check this textview is local or global variable. If global, it's only reference to the last item - then check the last item change? OK if it's not. Let post full ur code.
回答3:
runOnUiThread(new Runnable() {
@Override
public void run() {
Debug.print("Updating UI ...");
owner.setText("Uploading ...");
invalidate();
requestLayout();
}
});
来源:https://stackoverflow.com/questions/29466552/android-runonuithread-not-updating-ui-elements