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

The Archive Base Latest Questions

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

Code: Button b = new Button(this); b.setText(m.group()); RelativeLayout.LayoutParams lP = new RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

  • 0

Code:

        Button b = new Button(this);
        b.setText(m.group());

        RelativeLayout.LayoutParams lP = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, 
                RelativeLayout.LayoutParams.WRAP_CONTENT);

        int iDELETE_AFTER_TEST_ID;

        if(bLast != null){
            /*
             * Add a new move button
             */
            iId = bLast.getId();
            lP.addRule(RelativeLayout.RIGHT_OF, iId);
            bLast = b;
            bLast.setId(iId + 1);
            iDELETE_AFTER_TEST_ID = iId + 1; 
        }else{
            /*
             * Add the first of the move buttons
             */
            bLast = b;
            bLast.setId(R.id.base_button_arrangement_id);
            lP.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

            iDELETE_AFTER_TEST_ID = R.id.base_button_arrangement_id;
        }

        b.setLayoutParams(lP);
        b.setPadding(20, 10, 20, 50);
        Log.d(TAG, " going to add = " + b.getId() + " class = " + b.getClass());
        rl.addView(b);
        mNumberofMoveOptions++;



        View v = findViewById(iDELETE_AFTER_TEST_ID);

        if(v != null){
            if(v.getClass() == Button.class){
                Log.d(TAG, " id = " + b.getId() + " class = " + b.getClass());
            }else{
                Log.e(TAG, "Corruption has occured - not button type: " + 
                        iDELETE_AFTER_TEST_ID + " class: " + v.getClass());
            }
        }else{
            Log.e(TAG, "Corruption has occured - view is null: " + iDELETE_AFTER_TEST_ID);
        }

Debug:

going to add = 2130968581 class = class android.widget.Button

Corruption has occured – not button type: 2130968581 class: class android.widget.TextView

Question:

So even though the debug clearly shows the widget getting created as a Button, when I query it directly afterwards it has been converted or changed into a TextView. Am I querying incorrectly, or is the ID getting recycled or is something else happening?

Buttons that I create before an after this particular one work perfectly fine and are created as and remain of the Button widget type.

Many thanks for any help in advance.

  • 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-25T11:22:16+00:00Added an answer on May 25, 2026 at 11:22 am

    Mark Murphy kindly answered on another board.

    The reason appears to be that fact that the seed of the ID’s is driven by a tool generated Id.

    Using a user defined Id seems to sort out this issue and some other random problems I was having that would not appear initially to be related at all but actually were.

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

Sidebar

Related Questions

TableLayout relativeLayout = (TableLayout)findViewById(R.id.ll1); TableRow row =new TableRow(this); Button button ; int counter =
I am using a Button created using following code LinearLayout ll = new LinearLayout(this);
I have some code that dynamically creates a new button through JavaScript that when
i have in xml tis code: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:id=@+id/mainLayout android:layout_width=wrap_content android:layout_height=wrap_content> <Button android:id=@+id/examp1 android:layout_width=wrap_content
i've the following code for button creation and on action of button , i'm
I am using VB.NET and below code on button click event. Protected Sub ibtnSendInvites_Click(ByVal
There is code for save button, but I can't see any code behind the
The following code shows a button that allows you to select a file (should
Here is the code for the button click event; Protected Sub CompetenciesButton_Click(ByVal sender As
I've written some code for a button action. First I'm creating a button UI

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.