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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:19:18+00:00 2026-05-28T02:19:18+00:00

I have a blank button on which I would like to assign a name,

  • 0

I have a blank button on which I would like to assign a name, a color, and store a date–all when a user long-presses that button. I would appreciate some guidance please.

  1. Is starting with a ContextMenu the right thing to do?
  2. From the ContextMenu, can I invoke other popup menus
    like an EditText view for the name, a date-picker for the date, and
    a color-picker for the color?

Any guidance on this kind of sub-menu invokation from a context menu is appreciated. Or if I have the wrong philosophy for assigning a name, color, and date to a button, please suggest another technique.

Thank you.

  • 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-28T02:19:18+00:00Added an answer on May 28, 2026 at 2:19 am

    For the button long click all you will need to do is this

    down.setOnLongClickListener(new OnLongClickListener() { 
        @Override
        public boolean onLongClick(View v) {
            // TODO Auto-generated method stub
            return true;
        }
    });
    

    Then to create a context menu you will need to create a menu resource.

    <?xml version="1.0" encoding="utf-8"?>
    <menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/new_game"
          android:icon="@drawable/ic_new_game"
          android:title="@string/new_game" />
    <item android:id="@+id/help"
          android:icon="@drawable/ic_help"
          android:title="@string/help" />
    </menu>
    

    Then in your activity override this method and inflate your context menu

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

    This is how you capture which item was selected and act accordingly to it

    @Override
    public boolean onContextItemSelected(MenuItem item) {
    AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
     switch (item.getItemId()) {
     case R.id.edit:
    editNote(info.id);
    return true;
    case R.id.delete:
    deleteNote(info.id);
    return true;
    default:
    return super.onContextItemSelected(item);
    }
    }
    

    Now all you do is register your button for the context menu on long press like this..

    registerForContextMenu(down);  //Your button
    

    EDIT: To show a date picker just create a dialogDate picker and add

     showDialog(DATE_DIALOG_ID);
    

    in the switch statement of the context menu..

    Here is how you create a datepicker dialog

    private TextView mDateDisplay;
    private Button mPickDate;
    private int mYear;
    private int mMonth;
    private int mDay;
    
    static final int DATE_DIALOG_ID = 0;
    // get the current date
        final Calendar c = Calendar.getInstance();
        mYear = c.get(Calendar.YEAR);
        mMonth = c.get(Calendar.MONTH);
        mDay = c.get(Calendar.DAY_OF_MONTH);
    
    // the callback received when the user "sets" the date in the dialog
    private DatePickerDialog.OnDateSetListener mDateSetListener =
            new DatePickerDialog.OnDateSetListener() {
    
                public void onDateSet(DatePicker view, int year, 
                                      int monthOfYear, int dayOfMonth) {
                    mYear = year;
                    mMonth = monthOfYear;
                    mDay = dayOfMonth;
    
                }
            };
    
    @Override
     protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
        return new DatePickerDialog(this,
                    mDateSetListener,
                    mYear, mMonth, mDay);
    }
    return null;
    

    }

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

Sidebar

Related Questions

I have a huge dictionary of blank values in a variable called current like
I have an access table which has some cells as blank ( no data
I have a Customer class which has a representative field....this field is initially blank
I have the following code which works when i put it in any blank
I have a WPF Menu and a Tab control. I would like the list
I have a button that features a grid which in turn contains an image.
I have an aspx page which houses an iframe. When a button is clicked,
I have in my page a button which when clicked displays a div (popup
I have a GUI with a flat style for the buttons. I would like
I have a bit of HTML code that I would like to change based

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.