Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I create a clickable item in menu to open a new activity?
    text
    copied!<p>I have made an app with a lot of buttons and activities. I'm having trouble though understanding how to start a new activity through a button that is in my menu (when the menu button is clicked on phone) (inflatable menu). This is my code for the menu connected to my activity:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt; &lt;item android:id="@+id/item1" android:title="@string/menu_home"&gt;&lt;/item&gt; &lt;/menu&gt; </code></pre> <p>Here is my activities in Java:</p> <pre><code>package com.gmail.derekcraigsmith.nanaimobus; import android.os.Bundle; import android.app.Activity; import android.content.ClipData.Item; import android.content.Intent; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.PopupMenu; import android.widget.PopupMenu.OnMenuItemClickListener; public class Route1TimesCcMonfriAActivity extends Activity implements OnMenuItemClickListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.route1_times_cc_monfri_a); } public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.route1_times_cc_monfri_a, menu); return true; } @Override public boolean onMenuItemClick(MenuItem item) { // TODO Auto-generated method stub return false; } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload