is also transplanted from the MTK SDK, you can classify the notes.
Specific code can be viewed on GitHub, linked at the end of the article. Here are the following:
Main Activity,note list:
Package Com.zms.notebook;import Android.app.actionbar;import Android.app.alertdialog;import Android.app.listactivity;import Android.app.progressdialog;import Android.content.componentname;import Android.content.contenturis;import Android.content.dialoginterface;import Android.content.intent;import Android.net.uri;import Android.os.bundle;import Android.util.log;import Android.view.actionmode;import Android.view.gravity;import Android.view.layoutinflater;import Android.view.menu;import Android.view.MenuInflater ; Import Android.view.menuitem;import Android.view.view;import Android.view.viewgroup;import Android.view.viewgroup.layoutparams;import Android.widget.adapterview;import Android.widget.adapterview.onitemlongclicklistener;import Android.widget.button;import Android.widget.ListView; Import Android.widget.popupmenu;import Android.widget.progressbar;import Android.widget.textview;import Android.widget.toast;import Com.zms.notebook.noteadapter.noteitem;import Com.zms.notebook.NotePad.NotEs;import Java.util.locale;public class Noteslist extends Listactivity implements Onitemlongclicklistener {private STA Tic final String TAG = "Noteslist"; Public TextView Countview; Public Noteadapter Noteadapter; Private ProgressDialog mpdialogdeleting; Private Modecallback Mactionmodelistener = new Modecallback (); Public Actionmode Mactionmode; Private Button Mselecteditemsview; Private Notewaitcursorview Mwaitcursorview; Private TextView mloadingnotes; Private View Mloadingcontainer; Private ProgressBar mprogress; @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setdefaultkeymode (Default_keys_shortcut); Setcontentview (R.layout.noteslist_item_main); ActionBar ActionBar = Getactionbar (); Actionbar.sethomebuttonenabled (FALSE); ViewGroup view = (ViewGroup) layoutinflater.from (this). Inflate (R.layout.notelist_action_bar, NULL); ActionBar. Setdisplayoptions (Actionbar.display_show_custom, Actionbar.display_show_custom); Actionbar.setcustomview (view, New Actionbar.layoutparams (Layoutparams.wrap_content, LAYOUTP Arams. Wrap_content, Gravity.center_vertical | Gravity.right)); Countview = (TextView) View.findviewbyid (R.id.note_count); Getlistview (). Setonitemlongclicklistener (this); Mloadingnotes = (TextView) Findviewbyid (r.id.loading_notes); Mloadingcontainer = Findviewbyid (R.id.loading_container); Mprogress = (ProgressBar) Findviewbyid (r.id.progress_loading); Mprogress.setvisibility (View.gone); Mwaitcursorview = new Notewaitcursorview (this, Mloadingcontainer, mprogress, mloadingnotes); } @Override protected void Onresume () {super.onresume (); LOG.I (TAG, "Mactionmode =" + Mactionmode + "\nsflagnoteschanged" + notes.sflagnoteschanged); if (mactionMode = = NULL && notes.sflagnoteschanged) {queryupdatedata (); Notes.sflagnoteschanged = false; } if (Notes.ssavenoteflag) {Toast.maketext (this, r.string.note_saved, Toast.length_long). Show (); Notes.ssavenoteflag = false; } else if (notes.ssavenonote) {Toast.maketext (this, R.string.save_none, Toast.length_long). Show (); Notes.ssavenonote = false; }} @Override protected void OnDestroy () {Super.ondestroy (); Noteadapter = null; Notes.sflagnoteschanged = true; } public void Queryupdatedata () {log.i (TAG, "queryupdatedata"); Mwaitcursorview.startwaitcursor (); Invalidateoptionsmenu (); Noteadapter = new Noteadapter (this, null, 0); Queryhandler QH = new Queryhandler (This.getcontentresolver (), this); Qh.startquery (0, Mwaitcursorview, Notes.content_uri, notes.projection, NULL, NULL, notes.ssortorder); } @Override Public boolean Oncreateoptionsmenu (Menu menu) {menuinflater inflater = Getmenuinflater (); Inflater.inflate (R.menu.list_options_menu, menu); Intent Intent = new Intent (null, Notes.content_uri); Intent.addcategory (intent.category_alternative); Menu.addintentoptions (menu.category_alternative, 0, 0, New ComponentName (this, noteslist.class), NULL, inte NT, 0, NULL); return Super.oncreateoptionsmenu (menu); @Override public boolean Onprepareoptionsmenu (Menu menu) {super.onprepareoptionsmenu (menu); if (Notes.snotecount = = 0 | | mwaitcursorview.getquerystatus ()) {Menu.finditem (r.id.menu_muti_delete). setEnable D (FALSE); Menu.finditem (r.id.menu_sort_by_modify). SetEnabled (false); Menu.finditem (R.id.menu_sort_by_tab). SetEnabled (false); } else {Menu.finditem (r.id.menu_muti_delete). SetEnabled (True); Menu.finditem (r.id.menu_sort_by_modify). SetEnabled (True); Menu.finditem (R.id.menu_sort_by_tab). SetEnabled (True); } return true; } @Override public boolean onoptionsitemselected (MenuItem item) {Intent it; Switch (Item.getitemid ()) {Case r.id.menu_add:it = new Intent (this, noteedit.class); This.startactivity (IT); return true; Case R.id.menu_muti_delete:deleteallnotes (); return true; Case r.id.menu_sort_by_tab:notes.ssortorder = "Notegroup desc, modified desc"; Queryupdatedata (); return true; Case R.id.menu_sort_by_modify:notes.ssortorder = "Modified DESC"; Queryupdatedata (); return true; Default:return super.onoptionsitemselected (item); }} @Override protected void Onlistitemclick (ListView l, View v, int position, long id) {NoteItem noteite m = (NoteItem) l.getadapter (). GetItem (PositiON); Uri uri = Contenturis.withappendedid (Notes.content_uri, noteitem.id); if (Mactionmode! = null) {noteadapter.checkboxclickaction (position); Mselecteditemsview.settext (GetString (R.string.selected_item_count, notes.sdeletenum)); if (Notes.sdeletenum = = 0) {mactionmode.finish (); }} else {Intent it = new Intent (this, notereading.class); It.setdata (URI); This.startactivity (IT); }} @Override public Boolean Onitemlongclick (adapterview parent, view view, int position, long ID) { Notes.sdeletenum = 1; Mactionmode = Startactionmode (Mactionmodelistener); Noteadapter.checkboxclickaction (position); return true; } Private class Modecallback implements Actionmode.callback {private View mmultiselectactionbarview; @Override public boolean Oncreateactionmode (Actionmode mode, Menu menu) {menuinflater inflater = Getmenuinflater (); Inflater.inflate (R.menu.list_delete_menu, menu); if (Mmultiselectactionbarview = = null) {Mmultiselectactionbarview = Layoutinflater.from (noteslist.this) . Inflate (R.layout.noteslist_item_delete_action_bar, NULL); } mode.setcustomview (Mmultiselectactionbarview); ((TextView) Mmultiselectactionbarview. Findviewbyid (R.id.select_items)). SetText (GetString ( R.string.selected_item_count, Notes.sdeletenum)); Mmultiselectactionbarview.setvisibility (view.visible); Mselecteditemsview = (Button) mmultiselectactionbarview. Findviewbyid (R.id.select_items); Mselecteditemsview.setonclicklistener (New View.onclicklistener () {@Override public void OnC Lick (View v) {PopupMenu popup = new POpupmenu (Noteslist.this, v); Popup.getmenuinflater (). Inflate (R.menu.multi_delete_action_bar, Popup.getmenu ()); Popup.setonmenuitemclicklistener (New Popupmenu.onmenuitemclicklistener () {@Override public boolean Onmenuitemclick (MenuItem item) {int id = item.getitemid (); if (id = = r.id.menu_all_select) {NOTEADAPTER.SELECTALLORNOCHECKBO X (TRUE); Mselecteditemsview.settext (GetString (R.string.selected_item_count, Notes.sdeletenum)); } else if (id = = R.id.menu_no_select) {mactionmode.finish (); } else {return true; } RetuRN false; } }); Menu PopupMenu = Popup.getmenu (); MenuItem Selectallitem = PopupMenu. FindItem (R.id.menu_all_select); MenuItem Unselectallitem = PopupMenu. FindItem (R.id.menu_no_select); if (Notes.sdeletenum >= noteadapter.getcount ()) {if (Selectallitem! = null) { Selectallitem.setvisible (FALSE); } if (Unselectallitem! = null) {unselectallitem.setvisible (true); }} else {if (Selectallitem! = null) { Selectallitem.setvisible (TRUE); } if (Unselectallitem! = null) {unselectallitem.setvisible (false); } } popup.show (); } }); Getlistview (). Setlongclickable (false); return true; } @Override public boolean onprepareactionmode (actionmode mode, menu menu) {return true; } @Override public void Ondestroyactionmode (Actionmode mode) {log.i (TAG, "Ondestroyactionmode") ; Mmultiselectactionbarview.setvisibility (View.gone); Invalidateoptionsmenu (); Getlistview (). Setlongclickable (True); Mactionmode = null; Noteadapter.selectallornocheckbox (FALSE); } @Override public Boolean onactionitemclicked (final actionmode mode, MenuItem Item) {Switch (it Em.getitemid ()) {case r.id.menu_delete:mutideleteselectnotes (); Break Default:break; } return true; }} private void MutideLeteselectnotes () {if (Notes.sdeletenum > 0) {alertdialog.builder bld = new Alertdialog.builder (thi s); Bld.setpositivebutton (GetString (R.STRING.DELETE_CONFIRM_OK), new Dialoginterface.onclicklistener () { @Override public void OnClick (Dialoginterface dialog, int which) { Dialog.dismiss (); Begindeletenotes (Notes.noteslist_delete_token); } }); Bld.setnegativebutton (GetString (r.string.delete_confirm_cancel), null); Bld.setcancelable (TRUE); Bld.setmessage (getString (r.string.delete_confirm)); if (Notes.sdeletenum > 1 && locale.getdefault (). GetLanguage (). Equals ("en")) { Bld.setmessage (getString (r.string.delete_confirm)); } else {bld.setmessage (getString (r.string.delete_confirm_one)); } Bld.seticonattribute (Android. R.attr.alertdialogicon); Bld.settitle (getString (r.string.delete_confirm_title)); Alertdialog dlg = Bld.create (); Dlg.show (); } else {Toast.maketext (this, r.string.no_selected, Toast.length_long). Show (); }} public void begindeletenotes (int token) {log.i (TAG, "begindeletenotes"); Mpdialogdeleting = Progressdialog.show (This, "", GetString (r.string.delete_progress), true); Queryhandler QH = new Queryhandler (This.getcontentresolver (), this); LOG.I (TAG, "noteadapter.getfilter () = =" +noteadapter.getfilter ()); Qh.startdelete (token, mpdialogdeleting, Notes.content_uri, Noteadapter.getfilter (), NULL); private void Deleteallnotes () {Alertdialog.builder bld = new Alertdialog.builder (this); Bld.setpositivebutton (GetString (R.string.delete_confirM_OK), new Dialoginterface.onclicklistener () {@Override public void OnClick (dialoginterface dialog, int which) {Dialog.dismiss (); for (int i = 0; i < noteadapter.list.size (); i++) {Noteadapter.list.get (i). Isselect = true; } begindeletenotes (Notes.noteslist_delete_all_token); } }); Bld.setnegativebutton (GetString (r.string.delete_confirm_cancel), null); Bld.setcancelable (TRUE); Bld.setmessage (getString (r.string.delete_confirm)); Bld.setmessage (getString (r.string.delete_all_notes_confirm)); Bld.seticonattribute (Android. R.attr.alertdialogicon); Bld.settitle (getString (r.string.delete_confirm_title)); Bld.create (). Show (); }}
Reprint Please specify source: Zhou Mushi's CSDN blog http://blog.csdn.net/zhoumushui
my github: Zhou Mushi's GitHub Https://github.com/zhoumushui
Android Notepad Notebook