Notepad for Android projects (7)-----Deletion, recovery, and emptying of handwriting functions

Source: Internet
Author: User

The previous section adds handwriting to Notepad, but does not implement the functions of the bottom button, which is the first step to undo, redo, and empty the function.

Because the screen will not be recorded as a GIF picture, so it is given as a picture, not very image, do not look like:

Obviously, you need to add the item click event for the bottom gridview:

Private GridView Paint_bottommenu;
Paint_bottommenu = (GridView) Findviewbyid (r.id.paintbottommenu);p Aint_bottommenu.setonitemclicklistener (new Menuclickevent ());

The following is the implementation of specific functions in the listener:

1. Delete function

1) Get the last word position

2) Set the No. 0 to the penultimate position to the content of the custom edittext, and indirectly implement the function of removing the last word.

3) Update the position of the last word as the last word after deletion

3) The deleted word is stored in the list (actually stored in the stack better, because is advanced after out), for recovery.

The code is as follows:

  Private arraylist<charsequence> Deletechar = new arraylist<charsequence> ();
Delete case 2:editable Editable = Et_handwrite.gettext ();//Find the last handwritten word and delete the last handwriting int selectionend = et_ Handwrite.getselectionend ();  System.out.println ("end =" + Selectionend);  if (Selectionend < 1) {  et_handwrite.settext ("");  }  else if (selectionend = = 1) {  et_handwrite.settext ("");  Charsequence deletecharseq = editable.subsequence (0,1);  Deletechar.add (DELETECHARSEQ);  }  else{  System.out.println ("delete");  Charsequence charseq = editable.subsequence (0, selectionEnd-1);  Charsequence deletecharseq = editable.subsequence (selectionend-1,selectionend);  Et_handwrite.settext (CHARSEQ);  Et_handwrite.setselection (selectionEnd-1);  Save the deleted word to the list for recovery using  deletechar.add (DELETECHARSEQ);  } Break


2. Recovery function:

1) Remove the last element from the delete list

2) Add the removed element at the end of the custom EditText

3) Delete the last element from the drop-down list

Recover case   3:  //Remove the element in the delete list  int length = Deletechar.size ();  if (length > 0) {  et_handwrite.append (Deletechar.get (Deletechar.size ()-1));  Deletechar.remove (Deletechar.size ()-1);  }    Break

3. Clear function:
1) Create dialog, popup whether delete prompt

2) Add Positivebutton and Setnegativebutton to Dialog

3) in Positivebutton Click event, set the content of the custom edittext to empty

Empty screen Case 4:  if (et_handwrite.getselectionend () > 0) {  alertdialog.builder builder = new Builder ( Handwriteactivity.this); Builder.settitle ("Are you sure you want to clear all?" Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick ( Dialoginterface dialog, int which) {Et_handwrite.settext ("");d Ialog.cancel ();}}); Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener () {@Overridepublic void OnClick (dialoginterface dialog, int which) {dialog.cancel ();}});D Ialog dialog = Builder.create ();d ialog.show ();} Break


In this way, three basic features of handwriting have been implemented, for setting the thickness and color of the brush, do it later.

Notepad for Android projects (7)-----Delete, restore, and empty handwriting

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.