On Aug 25, 8:34 am, Hitendrasinh Gohil <[email protected]> wrote: > There are 9 buttons in one box.I m repeating this box 9 times.There are 9 > different ids assign to 9 diff buttons. > > But how to determine button is clicked from which box as there are 9 same > boxes? >
There are a couple of different ways. One approach is that you can encode the box number and the button number in the ID. E.g. Assuming the box numbers and the button numbers are both in the range 1 to 9, then set the ID of each button to ((box_number * 10) + button_number). Then in the OnClick the box number is the ID / 10 and the button number is the ID % 10. Another approach is to create a little object that contains the button's box and button number. You can then attach an instance of this object to each button using setTag(Object) and in the OnClick you can retrieve the object with getTag(). This approach is much more flexible than having "smart" IDs because the class you attach to the views can easily be extended later to hold additional useful info, but it's a bit heavier. - Dave -- 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

