When redrawing the project after calling ‘invalidateViews()’
When does the project redraw after calling invalidateViews()
?
I
asked because I tried to refresh listItems
after bg-thread notify image rsc download.
But there are no updates. A new icon is drawn only after exiting and re-entering.
I have an activity of type adapter
SettingValueAdapter extends BaseAdapter
It has one member:
private SettingsValue[] value;
It has two interesting methods:
@Override
public View getView(int position, View view, ViewGroup parent) {
AddressItem ai= (AddressItem)getItem(position);
DriveToNativeManager dnm = DriveToNativeManager.getInstance();
if (view == null) {
LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = li.inflate(R.layout.address_item, null);
}
view.setTag(R.id.addressItem,ai);
view.setTag(position);
view.findViewById(R.id.fullAddressItemCol).setVisibility(View.VISIBLE);
view.findViewById(R.id.addressItemTouch).setVisibility(View.GONE);
view.findViewById(R.id.addressItemImage).setVisibility(View.GONE);
if (ai != null) {
...
}
view.findViewById(R.id.addressItemIconLayout).setVisibility(View.VISIBLE);
Drawable icon = ResManager.GetSkinDrawable(ai.getIcon() + ".bin");
((ImageView)view.findViewById(R.id.addressItemIcon)).setImageDrawable(icon);
..
}
}
public void refreshListIcons() {
NativeManager nativeManager = AppService.getNativeManager();
SettingsValue[] values = new SettingsValue[categories.length];
for (int i = 0; i < categories.length; i++) {
values[i] = new SettingsValue(categories[i].value, nativeManager.getLanguageString(categories[i].displayString), false);
values[i].icon = ResManager.GetSkinDrawable(categories[i].iconName + ".bin");
// }
adapter.setValues(values);
this.runOnUiThread(new Runnable() {
@Override
public void run() {
adapter.notifyDataSetChanged();
}
});
}
I attached a callback to the bg-thread (C) image download process.
The callback switches to the UI thread and calls this refreshList
:
public void refreshSearchIconsOnSearchActivity() {
Runnable refreshViewEvent = new Runnable() {
@Override
public void run() {
Activity currentActivity = AppService.getActiveActivity();
if (currentActivity instanceof SearchActivity) {
Log.d("w", "refreshSearchIconsOnSearchActivity callback running in thread "
+ Thread.currentThread().getId() );
results list
((SearchActivity) currentActivity).refreshList();
}
}
};
AppService.Post(refreshViewEvent);
}
However, the picture has finished downloading and is not refreshed in the activity.
They only refresh when I leave and re-enter the activity.
What am I missing?
Solution
InvalidateViews only causes the listView to redraw itself. It doesn’t call getView to do this, it just resets the current View on the screen – basically it just does that
for(View child: getChildren()){
child.invalidate();
}
If you want to update the list, call notifyDataSetChanged on the adapter.