
调用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.
总结以上是内存溢出为你收集整理的java-调用`invalidateViews()`后重新绘制项目时全部内容,希望文章能够帮你解决java-调用`invalidateViews()`后重新绘制项目时所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)