java - How to send multiple functions/options to more than one list item? -


in profile.java class have listview , registered context menu , passed 2 items in profile.xml file named general , silent. want is, when user click on general, must show activate option , when user select silent, should show deactivate. activate , deactivate options in context_menu.xml file.

i giving of files.

profile.java

activity activity;       @override     protected void oncreate(bundle savedinstancestate) {          // todo auto-generated method stub         super.oncreate(savedinstancestate);         setcontentview(r.layout.profile);           activity = this;         //list items            listview lv  = (listview) findviewbyid(android.r.id.list);          registerforcontextmenu(lv);          setlistadapter(new arrayadapter<string>(this,                  android.r.layout.simple_list_item_1,                 getresources().getstringarray(r.array.profile)));         }        @override     public void oncreatecontextmenu(contextmenu menu, view v,             contextmenuinfo menuinfo) {         // todo auto-generated method stub          //menu.add("hello");         super.oncreatecontextmenu(menu, v, menuinfo);         menuinflater inflater = getmenuinflater();         inflater.inflate(r.menu.context_menu, menu);           } 

profile.xml

<?xml version="1.0" encoding="utf-8"?> <resources>     <string-array name="profile">         <item name="general">general</item>         <item name="silent">silent</item>        </string-array>  </resources> 

context_menu.xml

<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" >      <item android:title="@string/activate" android:id="@+id/item1"/>           <item android:title="@string/deactivate" android:id="@+id/item2"/>      </menu> 

yourlist.setonitemclicklistener(new onitemclicklistener() {     @override     public void onitemclick(adapterview<?> parent, view view,         final int position, long id) {         code     } } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -