MultiChoiceModeListener Android -
i want delete images gridview , works fine multichoicemodelistener , when select pictures want delete , want make images blue on margins , , blue on images . (like in android gallery , after longclick on random photo).thanks!
public class multichoicemodelistener implements gridview.multichoicemodelistener { @override public void onitemcheckedstatechanged(android.view.actionmode mode, int position, long id, boolean checked) { int selectcount = grid.getcheckeditemcount(); sparsebooleanarray checkeditempositions = grid.getcheckeditempositions(); int itemcount = grid.getcount(); switch (selectcount) { case 1: mode.setsubtitle("one picture selected"); break; default: mode.setsubtitle("" + selectcount + " pictures selected"); break; } } @override public boolean oncreateactionmode(android.view.actionmode mode, menu menu) { mode.settitle("select pictures"); mode.setsubtitle("one picture selected"); return true; } @override public boolean onprepareactionmode(android.view.actionmode mode, menu menu) { return true; } @override public boolean onactionitemclicked(android.view.actionmode mode, menuitem item) { return true; } @override public void ondestroyactionmode(android.view.actionmode mode) { } } @override public boolean onmenuitemselected(int featureid, menuitem item) { switch (item.getitemid()) { case r.id.action_add: // choose picture gallery intent photopickerintent = new intent(intent.action_pick, android.provider.mediastore.images.media.external_content_uri); file picturedirectory = environment.getexternalstoragepublicdirectory(environment.directory_pictures); string picturedirectorypath = picturedirectory.getpath(); uri data = uri.parse(picturedirectorypath); photopickerintent.setdataandtype(data, "image/* video*/"); startactivityforresult(photopickerintent, request_code_external_image); break; case r.id.action_delete: file filepath = environment.getexternalstoragedirectory(); sparsebooleanarray checkeditempositions = grid.getcheckeditempositions(); int itemcount = grid.getcount(); (int = itemcount - 1; >= 0; i--) { if (checkeditempositions.get(i)) { file dir5 = new file(filepath.getabsolutepath() + namealbum + filenamestrings[i]); file file3 = new file(string.valueof(dir5)); deleted = file3.delete(); } } if(deleted==true) { checkeditempositions.clear(); finish(); intent intent = new intent(this, albumactivity.class); intent.putextra("namealbum",namealbum); intent.putextra("namealbum2",namealbum2); startactivity(intent); }else { alertdialog.builder builder = new alertdialog.builder(albumactivity.this); builder.setmessage("keep hold on picture until can select pictures delete!"); builder.settitle("error!"); builder.setcancelable(false); builder.setneutralbutton("ok", new dialoginterface.onclicklistener() { @override public void onclick(dialoginterface dialog, int which) { dialog.dismiss(); } }); alertdialog dialog = builder.create(); dialog.show(); } break; } return super.onmenuitemselected(featureid, item); }
edit :
<selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_activated="true" android:drawable="@color/md_blue_400"/> <item android:state_pressed="true" android:drawable="@color/md_black_1000_50" /> </selector>
and selector you'll use background imageview in gridview !! , think work out things you!
i solved problem selector , if you're using multichoice listener on gridview , have make selector in drawble folder , , put bacground file gridview_item !! hope helps someone
Comments
Post a Comment