Hello Mark, thanks for looking at my problem.

Sorry it's not clear from the code, the first instance of the ID's is
driven by

bLast.setId(R.id.base_button_arrangement_id);

A user defined id rather than build tool assigned Id's, is it still
wrong to use the getId call?



On 6 Sep, 12:11, Mark Murphy <[email protected]> wrote:
> Do not use getId() as the basis for assigning other IDs to other
> widgets. You want to stay very far away from the numbers used by the
> build tools.
>
>
>
>
>
>
>
>
>
> On Tue, Sep 6, 2011 at 6:39 AM, slipp3ry <[email protected]> wrote:
> > 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 = 2130968576 class = class android.widget.Button
> > id = 2130968576 class = class android.widget.Button
>
> > going to add = 2130968577 class = class android.widget.Button
> > id = 2130968577 class = class android.widget.Button
>
> > going to add = 2130968578 class = class android.widget.Button
> > id = 2130968578 class = class android.widget.Button
>
> > going to add = 2130968579 class = class android.widget.Button
> > id = 2130968579 class = class android.widget.Button
>
> > going to add = 2130968580 class = class android.widget.Button
> > id = 2130968580 class = class android.widget.Button
>
> > going to add = 2130968581 class = class android.widget.Button
> > id = 2130968581 class = class android.widget.Button
>
> > going to add = 2130968582 class = class android.widget.Button
> > Corruption has occured - not button type: 2130968582 class: class
> > android.widget.TextView
>
> > going to add = 2130968583 class = class android.widget.Button
> > id = 2130968583 class = class android.widget.Button
>
> > going to add = 2130968584 class = class android.widget.Button
> > id = 2130968584 class = class android.widget.Button
>
> > going to add = 2130968585 class = class android.widget.Button
> > id = 2130968585 class = class android.widget.Button
>
> > going to add = 2130968586 class = class android.widget.Button
> > id = 2130968586 class = class android.widget.Button
>
> > going to add = 2130968587 class = class android.widget.Button
> > id = 2130968587 class = class android.widget.Button
>
> > going to add = 2130968588 class = class android.widget.Button
> > id = 2130968588 class = class android.widget.Button
>
> > 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.
>
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> >http://groups.google.com/group/android-developers?hl=en
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android 3.1 Programming Books:http://commonsware.com/books

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to