android - Selecting Menu Items has no effect -


i'm creating app android , wanted make items in context menu. wasn't problem , shown. when click on them, nothing happens.

i configured things needed configure, not able find problem. see something? here complete code of main-java-code.

import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.menu; import android.view.menuinflater; import android.view.menuitem; import android.webkit.webview;  public class mainactivity extends activity{  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);     webview mywebview = (webview) findviewbyid(r.id.webview);     mywebview.loadurl("abc");}     @override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu; adds items action bar if present.     getmenuinflater().inflate(r.menu.main, menu);     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.optionsmenu, menu);     return true; } public boolean onoptionsitemselected(menuitem about) {     //respond menu item selection     switch (r.menu.optionsmenu) {         case r.id.about:             startactivity(new intent(this, secondactivity.class));             return true;         case r.id.download:             startactivity(new intent(this, downloadactivity.class));             return true;         case r.id.impressum:             startactivity(new intent(this, impressumactivity.class));         case r.id.license:             startactivity(new intent(this, licenseactivity.class));     }     return false; } 

i want them show activitys, nothing happens.

thanks help

thanks phil, item selection working. here other codes, app breaks down every time select others.

here licenseactivity:

            import android.app.activity;             import android.os.bundle;             import android.webkit.webview;              /**              * created florent on 16.08.13.             */             public class licenseactivity extends activity {                         public void oncreate(bundle savedinstancestate) {             super.oncreate(savedinstancestate);                         webview mywebview = (webview) findviewbyid(r.id.licenseview);                         mywebview.loadurl("url");                         }             } 

second activity design activity, other activitys sames license activity.

i see misstake. need menuitems id inside switch using menuitem.getitemid(), , return return super.onoptionsitemselected();:

public boolean onoptionsitemselected(menuitem about) {     //respond menu item selection      switch (about.getitemid()) { // call here         case r.id.about:             startactivity(new intent(this, secondactivity.class));             return true;         case r.id.download:             startactivity(new intent(this, downloadactivity.class));             return true;         case r.id.impressum:             startactivity(new intent(this, impressumactivity.class));         case r.id.license:             startactivity(new intent(this, licenseactivity.class));     }      return super.onoptionsitemselected(about); // return instead of false } 

also, not forget register activities inside manifest file.

and make sure calling setcontentview(...) inside activity's oncreate() method.

public class licenseactivity extends activity {       public void oncreate(bundle savedinstancestate) {              super.oncreate(savedinstancestate);              setcontentview(r.layout.whateveryourlayoutis); // dont forget              webview mywebview = (webview) findviewbyid(r.id.licenseview);             mywebview.loadurl("url");      } } 

Comments

Popular posts from this blog

assembly - 8086 TASM: Illegal Indexing Mode -

Java, LWJGL, OpenGL 1.1, decoding BufferedImage to Bytebuffer and binding to OpenGL across classes -

javascript - addthis share facebook and google+ url -