我有一个系统,该系统在我选择的每个菜单选项上都在我的位图上放置一个小点。但是,我只希望一个点一次出现在我的位图上,因此当我单击第二个选项时,将出现另一个点。我有一个清除点方法,用于清除位图的点,我该如何实现,因此当我按下新按钮选项时,绘制了新的点,但将上一个点删除,而是从所有点删除所有点。
这是我的菜单选项
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.A:
fmob.mZoomView.setPoint(list.get(0).getLocationY(), list.get(0).getLocationX());
Toast.makeText(getBaseContext(), "Location A", Toast.LENGTH_SHORT).show();
return true;
case R.id.B:
Toast.makeText(getBaseContext(), "Selected Location B", Toast.LENGTH_SHORT).show();
fmob.mZoomView.setPoint(list.get(1).getLocationY(), list.get(1).getLocationX());
return true;
default:
return false;
}
}
这是我的清点方法
public void clearPoints() {
points.clear();
routepoints.clear();
invalidate();
}
如果您已经有一个事件侦听器,则应制作一种使用预制方法首先>清除位图的方法。必须按照该顺序完成,否则可能会出现语义误差。我只有这样构建的方法:
public void newPoint(int x, int y) /*throws InvalidPointException*/{
clearPoints();
//clear the points on the bitmap
updateBitmapDisplay();
//update the bitmap with the new points
addPoint(x, y);
//add the point to the bitmap
updateBitmapDisplay();
//update the bitmap with new points
}
然后,您必须使用自上而下的编程来使用可用的方法来制作这些方法。不过,我不完全理解您的问题,因此这对您可能没有用。对不起,如果事实证明是这种情况,您需要不同的东西。