Note that there are some explanatory texts on larger screens.

plurals
  1. POgetMenuInflater( ) method undefined issue in Android Context Menu creation
    primarykey
    data
    text
    <p>I am trying to create a context menu item inside a fragment. But I am facing issue with the getMenuInflater() method. It is undefined. I have imported all the necessary packages. Can anyone point out what I am doing wrong here?</p> <p>Here is my code: </p> <pre><code>import android.os.Bundle; import android.support.v4.app.Fragment; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.Gravity; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.MenuInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; import android.view.MenuItem; public class FeaturedFragment extends Fragment { public FeaturedFragment() { } public static final String ARG_SECTION_NUMBER = "section_number"; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.featured_fragment,container,false); registerForContextMenu(view); return view; } @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.toggleview_menu, menu); } } </code></pre> <p>here is my menu.xml</p> <pre><code> &lt;menu xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;item android:id="@+id/toggle_view" android:title="Change to ListView" android:icon="@drawable/collections_view_as_grid" android:showAsAction="always" /&gt; &lt;item android:id="@+id/grid_view" android:title="Grid View" android:orderInCategory="99" android:showAsAction="never" /&gt; &lt;item android:id="@+id/list_view" android:title="List View" android:orderInCategory="99" android:showAsAction="never" /&gt; &lt;/menu&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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