Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 924729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:24:21+00:00 2026-05-15T19:24:21+00:00

I am very new to Android. I am trying to build inflate a context

  • 0

I am very new to Android.

I am trying to build inflate a context menu within the sample GridView provided on the Android dev site. Eclipse tells me that the referenced items cannot be resolved, if someone could help find where I coded s.th. wrong, that would be great because I am stuck at the moment. Thanks.

I posted my entire code below. I get the error message at: if (item.getItemId() == R.id.menu_facebook) and the other R.id.’s


This is the ShareGalleryView.java file:

 import android.app.Activity; 
 import android.content.Context; 
 import android.os.Bundle; 
 import android.view.ContextMenu; 
 import android.view.MenuInflater; 
 import android.view.MenuItem; 
 import android.view.View; 
 import android.view.ViewGroup; 
 import android.view.ContextMenu.ContextMenuInfo;
 import android.widget.BaseAdapter;
 import android.widget.GridView;
 import android.widget.ImageView;
 import android.widget.AdapterView.AdapterContextMenuInfo;

 public class ShareGalleryView extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videogrid);

        GridView vGrid=(GridView) findViewById(R.id.vgrid);
        registerForContextMenu(vGrid);
        vGrid.setAdapter(new VideoAdapter(this));
    }

    public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
      super.onCreateContextMenu(menu, v, menuInfo);
      MenuInflater inflater = getMenuInflater();
      inflater.inflate(R.menu.menu_gallery_share, menu);
    }

    public boolean onContextItemSelected (MenuItem item){
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        if (item.getItemId() == R.id.menu_facebook)
        {
         //TODO open fb
            return true;

        }
        else if (item.getItemId() == R.id.menu_youtube)
        {
            //TODO open youtube
            return true;

        }
        else if (item.getItemId() == R.id.menu_email)
        {
         //TODO open email
            return true;

        }
        else if (item.getItemId() == R.id.menu_bluetooth)
        {
            // TODO send via bluetooth
            return true;

        }
    }

    public class VideoAdapter extends BaseAdapter {
        private Context mContext;

        public VideoAdapter(Context c) {
            mContext = c;
        }

        public int getCount() {
            return mThumbIds.length;
        }

        public Object getItem(int position) {
            return null;
        }

        public long getItemId(int position) {
            return 0;
        }

        // create a new ImageView for each item referenced by the Adapter
        public View getView(int position, View convertView, ViewGroup parent) {
            ImageView imageView;
            if (convertView == null) {  // if it's not recycled, initialize some attributes
                imageView = new ImageView(mContext);
                imageView.setLayoutParams(new GridView.LayoutParams(85, 85));
                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                imageView.setPadding(8, 8, 8, 8);
            } else {
                imageView = (ImageView) convertView;
            }

            imageView.setImageResource(mThumbIds[position]);
            return imageView;
        }

        // references to our images
        private Integer[] mThumbIds = {
                R.drawable.sample_2, R.drawable.sample_3,
                R.drawable.sample_4, R.drawable.sample_2,
                R.drawable.sample_6, R.drawable.sample_3,
                R.drawable.sample_4, R.drawable.sample_1

        };
    }
}

and this is the menu_gallery_share.xml file:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">   
  <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/menu_facebook"
          android:title="@string/Facebook" />
    <item android:id="@+id/menu_youtube"
          android:title="@string/YouTube" />
    <item android:id="@+id/menu_email"
          android:title="@string/Email" />
    <item android:id="@+id/menu_bluetooth"
          android:title="@string/Via Bluetooth" />
   </menu>
</menu>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:24:21+00:00Added an answer on May 15, 2026 at 7:24 pm

    Your menu xml file is defined incorrectly. A <menu> can only have <item>s and <group>s. Remove the extra <menu> you have defined and it should work properly. Your project probably stopped building as well and you can check that in Eclipse’s Android console. See this documentation for more information about the menu resource.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to Android Development. I am trying a sample application and
I am very new to android development. I am trying to a build an
I'm still very new to Android, but I am trying to keep up by
I'm new to Android dev. There's a very pretty state diagram of the MediaPlayer
I'm new at Eclipse and the Android applications making so here comes a very
I am very new to android development and have been trying to draw a
I'm very new to Android development and just started to study. What I'm trying
I am very new to java and trying to develop an Android app called
Ok so I am very new to android and I am just trying to
I'm very new to Android programming and I've been trying to figure out why

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.