Skip to content Skip to sidebar Skip to footer

How To Apply Undo And Redo Operation To Edittext On Button Click In Android

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 m

Solution 1:

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?

TextViewUndoRedomTextViewUndoRedo=newTextViewUndoRedo(edtNoteDescription);

btnUndo.setOnClickListener(newOnClickListener() {
    @OverridepublicvoidonClick(View v) {
        mTextViewUndoRedo.undo();
    }
});

Like I said in the comments, The Undo() method calls mEditHistory.getPrevious() but getPrevious() returns null because inside of it, it executes:

if (mmPosition == 0) { 
    returnnull; 
} 

When TextViewUndoRedo is created, a new EditHistory is created and inside of it mmPosition is initialized to 0. Since you are re-creating the object each time, mmPosition is always 0 and you get null back.

Post a Comment for "How To Apply Undo And Redo Operation To Edittext On Button Click In Android"