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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:53:46+00:00 2026-06-12T02:53:46+00:00

I have a context menu on a ListView. I would like to add a

  • 0

I have a context menu on a ListView.

I would like to add a special-case context list item for logged in users.

Let’s say there is a list of comments. But ONLY for the logged in user’s comments, there is a special context list-item called “Edit” (Obviously you don’t want other users to be able to edit comments outside of their own.

Here is my class extending application in which I usually check in for logged in users:

public class MyApp extends Application {

    public static boolean isUserLoggedIn = false;
    public static String username = null;
    public static SharedPreferences logInState;
    public static int ratescreen = 0;

    public static boolean userLogin() {

        return MyApp.isUserLoggedIn = true;
    }

    public static boolean userLogout() {

        return MyApp.isUserLoggedIn = false;
    }

    public static void setUser(String s) {

        MyApp.username = s;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        String PREFS_NAME = "LoginState";
        logInState = getSharedPreferences(PREFS_NAME,
                MODE_PRIVATE);
    }

}

Here is my context menu:

@Override
        public void onCreateContextMenu(ContextMenu menu, View v,
                ContextMenuInfo menuInfo) {

            super.onCreateContextMenu(menu, v, menuInfo);
            MenuInflater inflater = getActivity().getMenuInflater();
            inflater.inflate(R.menu.reviews_context, menu);
            menu.setHeaderTitle("Mark Comment as ...");
        }

        @Override
        public boolean onContextItemSelected(MenuItem item) {

            switch (item.getItemId()) {
            case R.id.helpful:

                new HelpfulTask().execute();

                Toast.makeText(getActivity(), "You have voted this up!",
                        Toast.LENGTH_SHORT).show();

                return true;
            case R.id.unhelpful:

                new UnHelpfulTask().execute();

                Toast.makeText(getActivity(), "You have voted this down!",
                        Toast.LENGTH_SHORT).show();

                return true;

            case R.id.spam:

                new SpamTask().execute();

                Toast.makeText(getActivity(),
                        "You have reported this as Spam or Offensive.",
                        Toast.LENGTH_SHORT).show();

                return true;

                    // Would like to add fourth option here but conditional if it is a comment from the currently logged in user.


            }
            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-06-12T02:53:48+00:00Added an answer on June 12, 2026 at 2:53 am

    Simple you add your Edit item depend on user login status in onCreateContextMenu

        @Override
            public void onCreateContextMenu(ContextMenu menu, View v,
                    ContextMenuInfo menuInfo) {
                // TODO Auto-generated method stub
    
                super.onCreateContextMenu(menu, v, menuInfo);
        // check if user logged-in so add Edit item to context menu.
                if (userLogin()) {
                    menu.add(0, MENU_ITEM_EDIT, 0, R.string.menu_edit);
                }
    //Add normall others menu items
                menu.add(0, MENU_ITEM_CALL, 0, R.string.menu_callContact);
    
    
    
            }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have item container style for list view like below : <ListView.ItemContainerStyle> <Style> <Setter
I have 1 activity, but would like to have multiple context menu's for different
I have a ListView and would like to remove a row item when the
so I have attached a context menu (right-click menu) to a wpf listview. unfortunately,
I have a list view filled with data. I set up a context menu
I have a button which opens a context menu with a list of various
I have a ListView, which can either have a context menu, or not. I
I have a list activity, and I chose to manually add the first item
I have a listview with two columns and I'm using a context menu to
I have a list view which has been registered for a context menu. For

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.