Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5954185
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:56:05+00:00 2026-05-22T17:56:05+00:00

I’m looking to loop through all the Togglebuttons I have in one activity and

  • 0

I’m looking to loop through all the Togglebuttons I have in one activity and do one of two things. In one case I want to set their values, in another case I want to read their values. Is the easiest way to do this to loop through the children, try to check their type for togglebutton and then preform the previously mentioned tasks?

Would I use something like this?

     for (int i = 0; i < rootView.getChildCount(); i++)
       if (Widget_Tag != null){   
       View Current_Widget = (View) rootView.getChildAt(i);          
       String Widget_Tag = (String) Current_Widget.getTag();
       if (Widget_Tag.equals("MyToggleButton")) {
         //do something
       }
     }

******UPDATE******

Working code as follows (thanks for answer), I nested another for-loop to dig down one child layer for my ToggleButtons:

    ViewGroup rootView = (ViewGroup) findViewById(R.id.LayoutHere);
    for (int i = 0; i < rootView.getChildCount(); i++) {
      ViewGroup nextLayout = (ViewGroup) rootView.getChildAt(i);
      for (int i2 = 0; i2 < nextLayout.getChildCount(); i2++) {
          View Current_Widget = nextLayout.getChildAt(i2);          
            if(Current_Widget instanceof ToggleButton) 
            {                     
              //Do Something
            }                         
      }         
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:56:06+00:00Added an answer on May 22, 2026 at 5:56 pm

    What you are doing would work if you have tagged your ToggleButton‘s with the String “MyToggleButton” like this:

    ToggleButton button = getSomeToggleButton();
    button.setTag("MyToggleButton");
    

    If you have not done something like the above previously, then your code snippet will not work. You could do an instanceof check on each View.

    if(Current_Widget instanceof ToggleButton) {// or instanceof MyToggleButton if that is a class of yours...
        //do something
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to loop through a bunch of documents I have to put
I have a jquery bug and I've been looking for hours now, I can't
I have a text area in my form which accepts all possible characters from
I'm looking for suggestions for debugging... If you view this site in Firefox or
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have some data like this: 1 2 3 4 5 9 2 6
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.