我在ListView活动中有一行,其中选择行时应更改图像。新图像与原始图像相同但更大(两倍大小)。再次取消选择时应该减少它(选择是使用我的内部选择实现的,而不是android键盘选择类型)。
问题是当(选定)我使用 setImageResource() 更改 ImageView () 的图片(在绑定时)时,它不会在第一次单击时更新到我的 List 行中的新更大版本。绑定的第二次执行工作正常。这同样适用于被取消选择的旧项目。在第二次单击之前,对较小图标的更改不会生效。每次我选择当前选择的行之外的另一行并在第二次单击时再次开始正常工作时,问题都会重复出现。
我已经逐步完成了代码,看到我将正确的 id 传递给了 ImageView,事实证明,在同一行上显示黄色边框的另一个视图在选择/取消选择时更改为可见/隐藏。
对我来说,感觉 setImageResource() 不会立即刷新视图,但在视图或行上使用 invalidate() 根本没有效果。
这是一个错误(如何解决)还是我做错了什么?
代码:(来自我的持有人类,使用持有人模式 - 由适配器绑定方法执行)
@Override
public void refreshFromCursor(final Context context, final Cursor cursor) {
...
boolean selected = adapter.getSelectedPosition()==cursor.getPosition();
if (selected){
selectedIndicator.setVisibility(View.VISIBLE); // Show a "selected" yellow border indicator to the left
} else {
selectedIndicator.setVisibility(View.GONE); // Hide a "selected" yellow border indicator to the left
}
...
if (selected) completionResId = R.drawable.folder_selected;
else completionResId = R.drawable.folder;
...
statusIcon.setImageResource(completionResId); // !!!!! This is where I set the image that does not refresh/resize
...
}
还测试了交换
statusIcon.setImageResource(completionResId);
和
statusIcon.setImageDrawable(context.getResources().getDrawable(completionResId));
但有问题的行为没有任何变化