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 7798681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:04:16+00:00 2026-06-02T00:04:16+00:00

please have a look at the code below… i am creating a context menu

  • 0

please have a look at the code below…
i am creating a context menu and implementing the method onContextItemSelected but the problem is that when i press the reply item…the dialog on the delete case also appears and the activity also starts twice…means all the cases executes…the delete the reply and the forward case…what happens to be the problem please help

@Override
    public boolean onContextItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
        switch(item.getItemId())
        {
    case R.id.reply:
    {
            Intent i = new Intent();
             String s2 = (String) ((Cursor) getListView().getItemAtPosition(info.position))
                    .getString(2);
             i.putExtra("number", s2);
        //   Log.v("number", s2);
             i.setClass(this, CreateMessage.class);
            // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             startActivity(i);

    }   
        case R.id.delete:
        {

        final String s = (String) ((Cursor) getListView().getItemAtPosition(info.position))
                        .getString(1);

              dba = new DBAdapter(this);

                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Are you sure you want to delete?")
                       .setCancelable(false)
                       .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                            //   Log.v("", "You Clicked " + s);             


                            dba.delete("messages", "id=?", new String[] { s });
                            populate();
                            dba.close();
                           }
                       })
                       .setNegativeButton("No", new DialogInterface.OnClickListener() {
                           public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                           }
                       });
                AlertDialog alert = builder.create();
                alert.show();
        }

        case R.id.forward:
        {
            Intent i = new Intent();
            String s3 = (String) ((Cursor) getListView().getItemAtPosition(info.position))
                    .getString(4);
        //  Log.v("message", s3);
            i.putExtra("message", s3);
            i.setClass(this, CreateMessage.class);
            startActivity(i);
        }
default:

        return super.onContextItemSelected(item);
        }
    }

and here is the error from the logcat that is displayed in the logcat…

03-30 09:13:28.439: E/WindowManager(2273): Activity sms.app.Displayer has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@44eb95c8 that was originally added here

sms.app.Displayer is the class in which i am implementing the context menu..

and here is the code of the context menu file..

<menu xmlns:android="http://schemas.android.com/apk/res/android" >


    <item android:id="@+id/reply" android:title="Reply"></item><item
        android:id="@+id/forward"
        android:title="Forward">
    </item>
    <item android:id="@+id/delete" android:title="Delete Message">
    </item>

</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-06-02T00:04:17+00:00Added an answer on June 2, 2026 at 12:04 am

    Once check this code a minor change in your onContextItemSelected method::

    @Override
        public boolean onContextItemSelected(MenuItem item) {
            // TODO Auto-generated method stub
            AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
            switch(item.getItemId()){
            case R.id.reply:
                Intent i = new Intent();
                String s2 = (String) ((Cursor) getListView().getItemAtPosition(info.position))
                        .getString(2);
                i.putExtra("number", s2);
                //   Log.v("number", s2);
                i.setClass(this, CreateMessage.class);
                // i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(i);
                break;
            case R.id.delete:   
    
                final String s = (String) ((Cursor) getListView().getItemAtPosition(info.position))
                        .getString(1);
    
                dba = new DBAdapter(this);
    
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setMessage("Are you sure you want to delete?")
                .setCancelable(false)
                .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        //   Log.v("", "You Clicked " + s);             
    
    
                        dba.delete("messages", "id=?", new String[] { s });
                        populate();
                        dba.close();
                    }
                })
                .setNegativeButton("No", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        dialog.cancel();
                    }
                });
                AlertDialog alert = builder.create();
                alert.show();
            break;
    
            case R.id.forward:
                Intent i = new Intent();
                String s3 = (String) ((Cursor) getListView().getItemAtPosition(info.position))
                        .getString(4);
                //  Log.v("message", s3);
                i.putExtra("message", s3);
                i.setClass(this, CreateMessage.class);
                startActivity(i);
            break;
            }
            return true;
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please have a look at the code below: import string from collections import defaultdict
Please have a look on the code below .. <div id=click_me>Save</div> <div id=blocks_sortable> <div
Could you please have a look at my code below. #!C:\Perl\bin\perl.exe use strict; use
am new here. i have a slight problem; PLease look at the following code
Please have a look at the code below (excerpt from a C# book): public
Please have a look at the code below: - (NSArray *)requestEntities:(NSString *)entityName { NSFetchRequest
Please have a look at the below SQL code. DECLARE @RET TABLE(OID BIGINT NOT
I have a query on this. Please look at the sample code below: UIButton
Please have a look on code written below. I am trying to have a
Please have a look at my code below. It's not working and I don't

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.