我该如何实施UNDO / REDO?

时间:2013-03-26 14:02:17

标签: android paint undo redo

您好我想在我的绘画应用程序中实现撤消/重做功能。

FirstActivity.java

    imageViewUndo = (ImageView)this.findViewById(R.id.imageViewUndo);
    imageViewUndo.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            myView.setMode(15); //undo

        }
    });
    imageViewRedo = (ImageView)this.findViewById(R.id.imageViewColor);
    imageViewRedo.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            myView.setMode(16); //redo

CanvasView.java在这里我觉得有些不对劲。

public class CanvasView extends View{

private ArrayList<Path> undonePaths = new ArrayList<Path>(); 
private ArrayList<Path> paths = new ArrayList<Path>();


public void onClickUndo () { 
    if (paths.size()>0) { 
       undonePaths.add(paths.remove(paths.size()-1));
       invalidate();
     }
}

public void onClickRedo (){
   if (undonePaths.size()>0) { 
       paths.add(undonePaths.remove(undonePaths.size()-1));
       invalidate();
   } 
}

我想提前感谢你!

0 个答案:

没有答案