android - How to close ListView's Contextual Action Mode on fragment destroy method -


i've succesfully implemented cab listview in fragment , work fine -> when hit or when change displayed fragment through navigation drawer, cab stays opened. need close cab in ondestroy method. i've tried this:

listview.clearchoices(); listview.cancellongpress(); 

but has no effect cab. solutions here?

i found pretty easy way how handle this:

1) make global variable of type actionmode:

actionmode actionmode = null; 

2a) assign actionmode in oncreateactionmode() method:

@override public boolean oncreateactionmode(actionmode mode, menu menu) {     getactivity().getmenuinflater().inflate(r.menu.action_mode, menu);     actionmode = mode;     return true; } 

2b) put in ondestroyactionmode() method:

@override public void ondestroyactionmode(actionmode mode) {     actionmode = null; } 

3) override ondestroy() method (you can use onpause() if want close cab every time fragment paused, may annoying users):

@override public void ondestroy() {     super.ondestroy();      //destroy action mode     if(actionmode != null)         actionmode.finish(); } 

that's it, every time you'll replace fragment, cancel actionmode.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -