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

  • Home
  • SEARCH
  • 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 554559
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:43:22+00:00 2026-05-13T11:43:22+00:00

I can not get the ContextMenuResource to return the correct information that I am

  • 0

I can not get the ContextMenuResource to return the correct information that I am looking for.

At times it returns what I want, other times not so much so.

 public class montypython extends Activity implements OnClickListener {
    private static final int SAVE_SOUND = 0;

    // Tag to easily locate errors in the log file.

    private static final String TAG = "Monty";

    // Declares the buttons.

    Button button0;
    Button button1;
    Button button2;
    Button button3;
    Button button4;
    Button button5;
    Button button6;
    Button button7;
    Button button8;
    Button button9;
    Button button10;
    Button button11;
    Button button12;
    Button button13;
    Button button14;
    Button button15;
    Button button16;
    Button button17;
    Button button18;
    Button button19;
    Button button20;
    Button button21;
    Button button22;
    Button button23;
    Button button24;
    Button button25;

    // Makes contextMenuResource available for use in other methods.

    public int contextMenuResource;

    // Makes MediaPlayer (mp) null and ready to go.

    MediaPlayer mp=null;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

    // Set Views and Listeners and Tags for buttons.

    button0=(Button)findViewById(R.id.button0);
    button0.setOnClickListener(this);
    button0.setTag(R.raw.a);
    button1=(Button)findViewById(R.id.button1);
    button1.setOnClickListener(this);
    button1.setTag(R.raw.b);
    button2=(Button)findViewById(R.id.button2);
    button2.setOnClickListener(this);
    button2.setTag(R.raw.c);
    button3=(Button)findViewById(R.id.button3);
    button3.setOnClickListener(this);
    button3.setTag(R.raw.d);
    button4=(Button)findViewById(R.id.button4);
    button4.setOnClickListener(this);
    button4.setTag(R.raw.e);
    button5=(Button)findViewById(R.id.button5);
    button5.setOnClickListener(this);
    button5.setTag(R.raw.f);
    button6=(Button)findViewById(R.id.button6);
    button6.setOnClickListener(this);
    button6.setTag(R.raw.g);
    button7=(Button)findViewById(R.id.button7);
    button7.setOnClickListener(this);
    button7.setTag(R.raw.h);
    button8=(Button)findViewById(R.id.button8);
    button8.setOnClickListener(this);
    button8.setTag(R.raw.i);
    button9=(Button)findViewById(R.id.button9);
    button9.setOnClickListener(this);
    button9.setTag(R.raw.j);
    button10=(Button)findViewById(R.id.button10);
    button10.setOnClickListener(this);
    button10.setTag(R.raw.k);
    button11=(Button)findViewById(R.id.button11);
    button11.setOnClickListener(this);
    button11.setTag(R.raw.l);
    button12=(Button)findViewById(R.id.button12);
    button12.setOnClickListener(this);
    button12.setTag(R.raw.m);
    button13=(Button)findViewById(R.id.button13);
    button13.setOnClickListener(this);
    button13.setTag(R.raw.n);
    button14=(Button)findViewById(R.id.button14);
    button14.setOnClickListener(this);
    button14.setTag(R.raw.o);
    button15=(Button)findViewById(R.id.button15);
    button15.setOnClickListener(this);
    button15.setTag(R.raw.p);
    button16=(Button)findViewById(R.id.button16);
    button16.setOnClickListener(this);
    button16.setTag(R.raw.q);
    button17=(Button)findViewById(R.id.button17);
    button17.setOnClickListener(this);
    button17.setTag(R.raw.r);
    button18=(Button)findViewById(R.id.button18);
    button18.setOnClickListener(this);
    button18.setTag(R.raw.s);
    button19=(Button)findViewById(R.id.button19);
    button19.setOnClickListener(this);
    button19.setTag(R.raw.t);
    button20=(Button)findViewById(R.id.button20);
    button20.setOnClickListener(this);
    button20.setTag(R.raw.u);
    button21=(Button)findViewById(R.id.button21);
    button21.setOnClickListener(this);
    button21.setTag(R.raw.v);
    button22=(Button)findViewById(R.id.button22);
    button22.setOnClickListener(this);
    button22.setTag(R.raw.w);
    button23=(Button)findViewById(R.id.button23);
    button23.setOnClickListener(this);
    button23.setTag(R.raw.x);
    button24=(Button)findViewById(R.id.button24);
    button24.setOnClickListener(this);
    button24.setTag(R.raw.y);
    button25=(Button)findViewById(R.id.button25);
    button25.setOnClickListener(this);
    button25.setTag(R.raw.z);

    // Registering ContextMenu's for long clicks.

    registerForContextMenu(button0);
    registerForContextMenu(button1);
    registerForContextMenu(button2);
    registerForContextMenu(button3);
    registerForContextMenu(button4);
    registerForContextMenu(button5);
    registerForContextMenu(button6);
    registerForContextMenu(button7);
    registerForContextMenu(button8);
    registerForContextMenu(button9);
    registerForContextMenu(button10);
    registerForContextMenu(button11);
    registerForContextMenu(button12);
    registerForContextMenu(button13);
    registerForContextMenu(button14);
    registerForContextMenu(button15);
    registerForContextMenu(button16);
    registerForContextMenu(button17);
    registerForContextMenu(button18);
    registerForContextMenu(button19);
    registerForContextMenu(button20);
    registerForContextMenu(button21);
    registerForContextMenu(button22);
    registerForContextMenu(button23);
    registerForContextMenu(button24);
    registerForContextMenu(button25);

}

    // Using the Tag to allow for simple media playing coding.

    @Override
    public void onClick(View vv) {
        if (mp !=null) {mp.stop();}
        mp=MediaPlayer.create(this, ((Integer)vv.getTag()).intValue());
        mp.start();
    }

    // Create ContextMenu's.

    @Override
    public void onCreateContextMenu(ContextMenu menu, View vv, ContextMenuInfo menuInfo) {
        super.onCreateContextMenu(menu, vv, menuInfo);
        contextMenuResource = ((((Integer) (vv.getTag())).intValue()));
        menu.setHeaderTitle(((Button)vv).getText());

        // contextMenuResource used here just to see what value it contains
        // when called it shows /res/raw/*.mp3 depending on which button

        menu.add(0, SAVE_SOUND, 0, contextMenuResource);
    }

    public boolean onContextItemSelected(MenuItem item) {

        switch(item.getItemId()) {
            case SAVE_SOUND:

        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);

        // contextMenuResource used here just to see what value it contains
        // when called it shows at least a seven digit integer (which makes sense to me)

        dialogBuilder.setMessage("You selected " + contextMenuResource);
        dialogBuilder.setCancelable(true);
        dialogBuilder.create().show();

        // Creates a directory on the SDCard 

            File sddir = new File("/sdcard/NetApex/Ringtones");
            if (!sddir.mkdirs()) {
                Log.e(TAG, "Create dir on sdcard failed");  
                return false;
                }   

        // The rest is commented out since I can't get the data I would like in order
        // to copy the file to the SDCard

        /*  InputStream fIn = getBaseContext().getResources().openRawResource(contextMenuResource);
            int size = 0;
            size = fIn.available();
            byte[] buffer = new byte[size];
            fIn.read(buffer);
            fIn.close();

            File rtNew = new File("/sdcard/NetApex/Ringtones"
            + contextMenuResource
            +".mp3");

            FileOutputStream rtFOS = null;
            rtFOS = new FileOutputStream(rtNew);
            rtFOS.write(buffer);
            rtFOS.flush();
            rtFOS.close();  */

            return true;  
        }
        return false;      
    }

    // Options menu created just to see it created

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);

        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.layout.menu, menu);

        return true;
    }

    // This makes the selection work

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()) {

        case R.id.quit:
            finish();
            return true;
        }
        return false;
    }
}
  • 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-13T11:43:22+00:00Added an answer on May 13, 2026 at 11:43 am

    contextMenuResource is the value of a raw resource ID. You should not be attempting to use it as a title for a context menu choice, as you are here:

    menu.add(0, SAVE_SOUND, 0, contextMenuResource);
    

    You do not appear to be using contextMenuResource anywhere else, and since you did not explain what your symptoms actually are, I’m having to guess.

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

Sidebar

Related Questions

I want to write Html format, but I can not even get a simple
So Google Analytics does not have an API that we can use to get
In silverlight, I can not get INotifyPropertyChanged to work like I want it to
I can get the element like this $(#txtEmail) but I'm not sure how to
I can't seem to get it to work. Perhaps I'm not even testing it
I get errors when viewing forms and there are not any. I can close
I can not get the difference between these sentences! would you please write some
I can not get to make this comparison in this simple code error ..
I can not get logs from some customers, can I use Google Urchin in
I can not get 'operator <' to compile for a weak_ptr using VS10. Am

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.