[android-developers] Is there (or should there be), a generateId() method for dynamically generated Views?
Is there (or should there be), a generateId() method for dynamically generated Views? Take the RadioGroup example in APIDemos|App|Views. Radio buttons are added dynamically. For each button, you have to call setId(). To be notified when a radio button is selected, you register a onCheckedChange listener on RadioGroup and the callback method is oncheckedChange(RadioGroup, int checkedId). Since we are notified only the id of the checked view, shouldn't there be a way to uniquely generate the id? Say, a View.generateId() method... In the example, the ids are statically defined in ids.xml. However this limits the number of radio buttons. I have a real world example too: a Radiogroup with each choice representing a Wifi hotspot. So one cannot know in advance the number of hotspots. - Anil -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Is there (or should there be), a generateId() method for dynamically generated Views?
On Mon, Aug 30, 2010 at 10:18 AM, Anil anil.r...@gmail.com wrote: Is there (or should there be), a generateId() method for dynamically generated Views? Addition seems to be sufficient. Since we are notified only the id of the checked view, shouldn't there be a way to uniquely generate the id? Say, a View.generateId() method... Why not radioButtonId++? In the example, the ids are statically defined in ids.xml. However this limits the number of radio buttons. IMHO, if you are concerned about the number of radio buttons, you should be using a ListView. -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Is there (or should there be), a generateId() method for dynamically generated Views?
It's also not quite correct that a radio button is only identified by its viewId. Using View.setTag (two versions), you can associate your own data item (s) with a view. However, I agree with Mark that using a ListView is quite likely to be a better solution. -- Kostya 30.08.2010 18:45, Mark Murphy пишет: On Mon, Aug 30, 2010 at 10:18 AM, Anilanil.r...@gmail.com wrote: Is there (or should there be), a generateId() method for dynamically generated Views? Addition seems to be sufficient. Since we are notified only the id of the checked view, shouldn't there be a way to uniquely generate the id? Say, a View.generateId() method... Why not radioButtonId++? In the example, the ids are statically defined in ids.xml. However this limits the number of radio buttons. IMHO, if you are concerned about the number of radio buttons, you should be using a ListView. -- 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 android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en