Common Listener for a bunch of radio groups

I have about 60 radio groups that I need to register a listener for. Currently this is how I do it:

    RadioGroup rg1 = (RadioGroup) getView().findViewById(;
    rg1 = (RadioGroup) getView().findViewById(;
    rg1 = (RadioGroup) getView().findViewById(;

and so on for the 60 radio groups. Is there a way to set all radio groups on the fragment to register to a common listener in a single statement or two without having to type out this much code? Thanks


If all the RadioGroup elements share the same parent, you could iterate using ViewGroup.getChildAt and ViewGroup.getChildCount. Something like this:

ViewGroup parent = (ViewGroup) findViewById(;
for (int i = 0; i < parent.getChildCount(); i++) {
    View currentView = parent.getChildAt(i);
    if (currentView instanceof RadioGroup) {
        ((RadioGroup) currentView).setOnCheckedChangeListener(this);

Need Your Help

E2E testing remote AngularJS application

testing angularjs cross-domain karma-runner end-to-end

I'm trying to realize E2E testing of existing AngularJS application with Karma Test Runner. My application is located on host1.internal and I'm on host2.internal. So in my karma config file I have:

Javascript functions not working when integrating two codes together

javascript jquery

these javascript functions are working perfectly separate, however when i try to write them in the same page they become inactive. All of the id and class names are correct. I have been fiddleing w...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.