Note that there are some explanatory texts on larger screens.

plurals
  1. PObeginner woes togglebutton arrays?
    text
    copied!<p>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.</p> <p>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</p> <pre><code>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 </code></pre> <p>any help or point in the right direction would be ace ta</p> <p>edit: this is my new code that crashes</p> <pre><code> 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&lt;128; i++) { ToggleButton tgl = new ToggleButton(this); tgl.setId(i); tgl.setOnCheckedChangeListener( this); layout.addView(tgl); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload