These days have been contact with the knowledge of Actionmode, here on the knowledge of their exposure to write down, will certainly be used to find the
Creation of 1.ActionMode
PrivateActionmode.callback Mcallback =NewActionmode.callback () {@Override Public Booleanonactionitemclicked (Actionmode arg0, MenuItem arg1) {FinalArraylist<griditem> SelectItem =Madapter.mselectitem; if(Arg1.getitemid () = =r.id.menu_delete) { NewAlertdialog.builder (Mcontext). Settitle (Mcontext.getstring (R.string.delete)). s Eticon (NULL). Setmessage (Mcontext.getresources (). getquantitystring (R.plurals.delet E_selection, MAdapter.mSelectItem.size ())). Setpositivebutton (Mcontext.getstring (R.string.ok),NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intWhichbutton) {DeleteImage da=Newdeleteimage (SelectItem); Da.execute (); }}). Setnegativebutton (Mcontext.getstring (r.string.cancel),NewDialoginterface.onclicklistener () { Public voidOnClick (Dialoginterface Dialog,intWhichbutton) {}}). Show (); } Else if(Arg1.getitemid () = =r.id.menu_share) {Intent Intent=computesharingintent (); Getactivity (). StartActivity (Intent.createchooser (Intent, getString (R.string.share))); } Else if(Arg1.getitemid () = =r.id.menu_select) { if(selectitem.size () = =mgirdlist.size ()) {cleargridlist (); } Else{selectallgridlist (); } updateselectnumber (); Madapter.notifydatasetchanged (); } return false; }
@Override Public BooleanOncreateactionmode (Actionmode arg0, Menu arg1) {layoutinflater layoutinflater=(Layoutinflater) getactivity (). Getsystemservice (Context.layout_inflater_service);//Add plain layout files, mostly displayed on top---- View CustomView= Layoutinflater.inflate (R.layout.funui_action_mode,NULL)///-----> Note It's layoutinflater.
Arg0.setcustomview (CustomView); Mselect=(TextView) Customview.findviewbyid (r.id.select); Menuinflater Inflater=arg0.getmenuinflater ();//Notice the difference with the above, this is used to add the menu
Inflater.inflate (R.menu.image_menu, arg1); This can also be used to set the state of the elements inside, using the method is Mselectitem = Menu.finditem (R.id.select_all);
return true; } @Override Public voidOndestroyactionmode (Actionmode arg0) {Setselectmode (false); Madapter.notifydatasetchanged (); } @Override Public BooleanOnprepareactionmode (Actionmode arg0, Menu arg1) {return false; } };
Explain
1.onactionitemclicked(), this method is mainly used to define the Actionmode menu item Click event Processing,MenuItem is the element inside, Just like the button in LinearLayout.
2.Oncreateactionmode(), this method is mainly used to define the display of the menu in the Actionmode, loading the menu layout, if you want to hide the individual elements, it is also handled in this area
You want to add a Select all feature, add the following code
Private void Cancelselect () { 266 for (Album album:malbumlist) { false; } MAdapter.mSelectAlbum.clear (); } Private void SelectAll () { mAdapter.mSelectAlbum.clear (); for (Album album:malbumlist) { true; MAdapter.mSelectAlbum.add (album); } }
In fact, this is to find the stored in the selected ListView, the ListView operation on the line
Android-actionmode use