3

调用后何时重绘项目invalidateViews()

listItems我问是因为我在 bg-thread 通知图像 rsc 下载后尝试刷新。

但是什么都没有更新。只有在退出并重新进入后才会绘制新图标。

我有一个adapter类型的活动SettingValueAdapter extends BaseAdapter

它有一个成员:

private SettingsValue[] values;

它有两个有趣的方法:

            @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);
    }

但是,图像已完成下载,并且不会在活动中刷新。

只有当我离开重新进入活动时,它们才会刷新。

我错过了什么?

4

1 回答 1

4

InvalidateViews 只会导致 listView 重绘自身。它不会调用 getView 来这样做,它只是重置屏幕上的当前值 - 基本上它只是这样做

for(View child: getChildren()){
    child.invalidate();
}

如果要更新列表,请在适配器上调用 notifyDataSetChanged。

于 2013-06-29T23:51:31.117 回答