How to use ActionMode with "setOnItemClickListener" method in ListView-Android? -


i have listview in project there actionmode shown clicking on each listview's item.

i this:

public class myactivity extends activity  { ... public void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.main); ...  listview.setonitemclicklistener(new adapterview.onitemclicklistener() {         @override         public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {             public boolean oncreateactionmode(final actionmode mode, menu menu) {                 mode.settitle("title");                 getmenuinflater().inflate(r.menu.menu, menu);                 return true;             }              @override             public boolean onprepareactionmode(actionmode mode, menu menu) {                 return true;             }              @override             public boolean onactionitemclicked(final actionmode mode, menuitem item) {                 switch (item.getitemid()) {                    ...buttons                     case r.id.donebtn:                           break;                 }                 return true;             }          }     });  } 

there problems in returns.this note shows each returns "can not return value method void return type"... how can solve it?

it seems you've messed listeners quite bit.

adapterview.onitemclicklistener has 1 method, namely onitemclick(). take here more info on

to start actionmode can use

activity.startactionmode(new myactionmodelistener()) 

your listener can this:

private class myactionmodelistener implements actionmode.callback {      @override     public boolean oncreateactionmode(actionmode mode, menu menu) {         menuinflater inflater = myactivity.this.getsupportmenuinflater();         inflater.inflate(r.menu.my_activity_action_mode, menu);         return true;     }      @override     public boolean onprepareactionmode(actionmode mode, menu menu) {         return false;     }      @override     public boolean onactionitemclicked(actionmode mode, menuitem item) {          switch (item.getitemid()) {             // handle clicks here         }          mode.finish();         return true;     }      @override     public void ondestroyactionmode(actionmode mode) {} } 

to start actionmode based on list item click, use like

listview.setonitemclicklistener(new adapterview.onitemclicklistener() {     @override     public void onitemclick(adapterview<?> adapterview, view view, int i, long l) {         myactivity.this.startactionmode(new myactionmodelistener());     } } 

Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -