Android 如何以编程方式调用onItemSelected?
在我调用notifyDataSetChanged之后,我从onItemSelected的所有引用都过期了 e、 g 轮换Android 如何以编程方式调用onItemSelected?,android,Android,在我调用notifyDataSetChanged之后,我从onItemSelected的所有引用都过期了 e、 g 轮换 public void rotateS(View v) { ImageView iv = onFront; Bitmap b = ((BitmapDrawable) iv.getDrawable()).getBitmap(); Matrix matrix = new Matrix(); matrix.postRo
public void rotateS(View v) {
ImageView iv = onFront;
Bitmap b = ((BitmapDrawable) iv.getDrawable()).getBitmap();
Matrix matrix = new Matrix();
matrix.postRotate(geg);
Bitmap bMapRotate = Bitmap.createBitmap(b, 0, 0, b.getWidth(),
b.getHeight(), matrix, true);
iv.setImageBitmap(bMapRotate);
geg = 90;
Log.d("rorate", "yes");
}
onFront
引用了旧的imageView,因此我不能再使用它了。我怎样才能再次调用已选中的
更详细一点:
我正在拍摄imageView并将其用于旋转
功能。它使用onFront,但将其替换为全局变量onFront1 | onFront2 | onFront3onFron1允许在图像出现在屏幕上时立即旋转图像,但在NOTIFYDATASETCHETCHANGE后图像将变得无效。
onFront2不受notifyDataSetChanged的影响,但它仅在录制屏幕后工作(符合逻辑)
onFront3根本不起作用。
我想要实现的是-保留对当前imageview的引用,并在imageview更新后立即更新它。最好在同一代码块上重新分配
前端
,在该代码块中调用notifyDataSetChanged
若在您的场景中无法做到这一点,那个么您需要额外的机制来跟踪ListAdapter中的负载
例如,您希望使用特定颜色标记选定的项目。
您可以引入ItemData类:
public class ItemData{
public bool IsSelected;
// some other data if you need, maybe link to the image view
}
ListAdapter应该使用这些对象的列表(listData)并实现getItem()方法:
在调用的侦听器中选择item-时
((ItemData)parent.getItem(position)).IsSelected = true;
然后,如果在先前选择的上方添加新项目,则还应在
listData
中添加新项目。以前所选项目的位置将更改,但关联的ItemData
实例不会更改。我尝试过(可能错误),但getView的(ImageView)视图和onItemSelected的(ImageView)视图似乎有所不同。请更清楚地描述您的场景。我更新了问题,你能根据新的更新修改你的答案吗?
public class ItemData{
public bool IsSelected;
// some other data if you need, maybe link to the image view
}
public Object getItem(int i) {
return this.listData.get(i);
}
((ItemData)parent.getItem(position)).IsSelected = true;