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 6787487
In Process

The Archive Base Latest Questions

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

just started messing with the android sdk and need to think about optimizing my

  • 0

just started messing with the android sdk and need to think about optimizing my code.
ive searched and done tutorials but it just doesnt click for togglebutton arrays.

this is an example of what i have, you can see if i have say 128 buttons its going to get messy.
i also need to know the checked state of the button

my activity class
private ToggleButton seqButton1;
private ToggleButton seqButton2;
blah.....
private ToggleButton seqButton128;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

seqButton1 = (ToggleButton) findViewById(R.id.btn1);
seqButton2 = (ToggleButton) findViewById(R.id.btn2);
....blah

any help or point in the right direction would be ace ta

edit:
this is my new code that crashes

    package trkrPkg.trackr;

import android.app.Activity;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.ToggleButton;

public class TrackerActivity extends Activity implements OnCheckedChangeListener {

     @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
       Toast.makeText(this, "Toggle Button:" + buttonView.getId() + " is checked: " + isChecked, Toast.LENGTH_SHORT).show();
    }


    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LinearLayout layout = (LinearLayout)findViewById(R.id.my_toggle_container);

        for (int i = 0; i<128; i++) {
            ToggleButton tgl = new ToggleButton(this);
            tgl.setId(i);
            tgl.setOnCheckedChangeListener( this);
                layout.addView(tgl); 
           }

    }
}
  • 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-26T17:22:20+00:00Added an answer on May 26, 2026 at 5:22 pm

    You could add the ToggleButtons dynamically instead of declaring them in xml and

     public class YourActivity extends Activity implements OnCheckedChangeListener {
    
        //..
    
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
           Toast.makeText(this, "Toggle Button:" + buttonView.getId() + " is checked: " + isChecked, Toast.LENGTH_SHORT).show();
        }
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
           super.onCreate(savedInstanceState);
           setContentView(R.layout.main);
    
           LinearLayout layout = (LinearLayout)findViewById(R.id.my_toggle_container);
    
           //..
           for (int i = 0; i<128; i++) {
            ToggleButton tgl = new ToggleButton(this);
            tgl.setId(i);
            tgl.setOnCheckedChangeListener(this);
                layout.addView(tgl); 
           }
           //...
        }
    }//end class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just started learning about servers, and I am messing around with Google's App
So I started messing around with gettext but I'm still puzzled about certain things,
I just started messing with android dev and I am trying to simply play
I just started thinking about creating/customizing a web crawler today, and know very little
I just started to learn Android, I'm trying to write a widget which is
I just started messing around with having my application store sessions in the database
I just started messing around with C#/.NET/mono and stuff, and I'm trying to make
I'm very new to Android development (just started today), and also very new to
Just picked up an Iconia A500 (yay $100 off coupon) and started messing with
this is my first question and I've been messing around with android for just

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.