I am trying to apply Undo and Redo operation while writing or applying effect to my EditText. For that i have downloaded class from this Link and then i have used it like this in my app.
For Undo
TextViewUndoRedo mTextViewUndoRedo = new TextViewUndoRedo(edtNoteDescription);
mTextViewUndoRedo.undo();
For Redo
TextViewUndoRedo mTextViewUndoRedo = new TextViewUndoRedo(edtNoteDescription);
mTextViewUndoRedo.redo();
But i don't know why this code does not work, I have put the log and check whether the function Undo is called or not and unfortunately i saw that it is calling this function but it goes inside below method.
if (edit == null) {
return;
}
I have also tried with some other solution with no luck, So if anyone who has implemented the same with this method or with any other method then please do suggest some code or way to implement this functionality.
Edit
btnUndo.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
TextViewUndoRedo mTextViewUndoRedo = new TextViewUndoRedo(edtNoteDescription);
mTextViewUndoRedo.undo();
}
});
Could the problem be that you are creating the
TextViewUndoRedo
object each time the button is clicked?That is why
EditHistory
is empty cause it's getting recreated each time. Wouldn't this work?Like I said in the comments, The
Undo()
method callsmEditHistory.getPrevious()
butgetPrevious()
returnsnull
because inside of it, it executes:When
TextViewUndoRedo
is created, a newEditHistory
is created and inside of itmmPosition
is initialized to 0. Since you are re-creating the object each time,mmPosition
is always 0 and you getnull
back.