Thanks Kostya,

Does anyone also happen to know how can we make a button that has been
created dynamically
set to "wrap_content" (as we do in the static mode) to make the
*button fit* neatly
around the text?

Thank you,
Sara


On Tue, Sep 7, 2010 at 2:11 PM, Kostya Vasilyev <[email protected]> wrote:

>  Right.
>
> The scope of aUIXButton is the inside of the loop, it does not persist
> until the later point in time when OnClickListener subclass is invoked.
>
> Moreover, the value of aUIXButton refers to all five buttons, one by one,
> as the loop rolls.
>
> Use this instead:
>
>
>      aUIXButton.setOnClickListener(new OnClickListener() {
>     @Override
>     public void onClick(View arg0) {
> *    Button button = (Button) arg0;
>     button.setText("Y");
> *    }});
>
> -- Kostya
>
> 07.09.2010 16:00, Sara Khalatbari пишет:
>
> Hi.
>
>  I have some dynamic buttons that are being generated inside a for loop.
>
>   for (int i = 0; i < 5 ; i++) {
>
>
>>   Button aUIXButton = new Button (SecondPage.this);
>
>  aUIXButton.setClickable(true);
>
>  aUIXButton.setText("X");
>
>
>>   aUIXButton.setOnClickListener(new OnClickListener() {
>
>  @Override
>
>  public void onClick(View arg0) {
>
>  aUIXButton.setText("Y");
>
>  }});
>
>  }
>
>
>  This is not working. It says
> "Cannot refer to a non-final variable aUIXButton inside an inner class
> defined in a different method"
>
>  & wants to change the modifier of  aUIXButton to final & I don't want to
> do that.
>
>  Does anyone know how can I fix this?
>
>  Thank you,
>
>  --
> 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
>
>
>
> --
> Kostya Vasilyev -- WiFi Manager + pretty widget -- 
> http://kmansoft.wordpress.com
>
>  --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
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