调用invalidateViews()之后何时重新绘制项目?
我问是因为我尝试在bg线程通知下载了图像rsc之后刷新listItems.
但是没有任何更新.仅在退出并重新进入新图标之后才绘制.
我有一个带有SettingValueAdapter类型的适配器扩展BaseAdapter的活动
它有一个成员:
私有SettingsValue []值;
它有两种有趣的方法:
@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();
}
});
}
我在bg-thread(c语言)图像下载过程中附加了一个回调.
回调将切换到ui线程并调用以下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);
}
但是,图像已完成下载,并且不会在活动中刷新.
仅当我离开重新输入活动时,它们才会刷新.
我想念什么?
解决方法:
InvalidateViews只是使listView重绘自身.它不会调用getView这样做,它只是在屏幕上重置当前屏幕-基本上是
for(View child: getChildren()){
child.invalidate();
}
如果要更新列表,请在适配器上调用notifyDataSetChanged.