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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T23:18:39+00:00 2026-05-20T23:18:39+00:00

I would like if anybody could help to solve the problem, that I’m trying

  • 0

I would like if anybody could help to solve the problem, that I’m trying to fix in my code. I’m really despearte!

I would like to know if it’s possible get from the contextmenu, all the information of the button that I created, and use the setText function later.

Ok, first of all I create a tablerow with some buttons (like a soundboard application)

for (int j = 0 ; index > 0 && j < 2 ; j++) {
    final CustomToggleButton tagB = new CustomToggleButton(this);
    tagB.setId(index);
    ...
    ...
    registerForContextMenu(tagB);
    tagB.setOnClickListener(new View.OnClickListener() {
          public void onClick(View v) {
               ....
          }
          ...
    }
}

Secondly, I let every button an “edit” option for changing the text in it:

@Override
 public void onCreateContextMenu(ContextMenu menu, View v,  ContextMenuInfo menuInfo) {
     AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo)menuInfo;
     menu.setHeaderTitle("Opciones de la etiqueta");
     menu.add(0, v.getId(), 0, "Edit");
 }

Finally I use onContextItemSelected for creating an EditText Alert and let the possibility of introduce the new text.

@Override
public boolean onContextItemSelected(final MenuItem item) {
    if (item.getTitle() == "Edit") {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);
        final EditText input = new EditText(this);
        alert.setView(input);
        alert.setTitle("Nombre del tag");
        alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                String value = input.getText().toString().trim();
                Log.v(null, "nombre del tag nuevo: "+value);
                Toast.makeText(getApplicationContext(), value,Toast.LENGTH_SHORT).show();
                int button_id = item.getItemId();   // BUTTON ID? 
                //CustomToggleButton tagB = (CustomToggleButton) findViewById(R.id.button_id);//DOESN'T WORK!!
                //CustomToggleButton tagB = (CustomToggleButton) findViewById(button_id); // NEITHER DOESN'T WORK!!
            }
        });
        alert.setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                dialog.cancel();
            }
        });
        alert.show();
        return true;
    }
    else return super.onContextItemSelected(item);
}

The problem is that I can’t use its id from R.java, because I have created the button programatically…

Is there any solution for this problem??

  • 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-20T23:18:39+00:00Added an answer on May 20, 2026 at 11:18 pm

    You don’t need the ID of the button. You need to reference the Button object you created via code.

    Edit: Just define the button object with the scope you require. You probably need class scope. You could use an array or list if you would like. Depending on how many buttons you have, that may be the way to go.

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

Sidebar

Related Questions

I would be grateful if anybody could help me out with this. I have
I was wondering whether anybody here could help with this problem I am having
I would like to use a language that I am familiar with - Java,
I wondered if anybody could help me with a technique to address the following
Does anybody know of a library or piece of software out there that will
I hope somebody could help me out, I have no idea how to solve
(please excuse that I didn't use aliases). I would like my query output to
I am currently working on a lab and would like to know how to
Hopefully somebody can point me to something that could help. What I'm doing is
Would like to get a list of advantages and disadvantages of using Stored Procedures.

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.