i’ve made a simple counter program, where i click the plus or minus button and it adds or removes 1 from a counter.
I would like to be able to add more counters: ex. counter1, counter2, counter3 etc.
Here’s an example of how i’m doing now with 2 counters, but as you can see i have declared my variables, and i would like to generate them automaticly
int counter, counter2;
ImageButton add, sub, add2, sub2, btnSet;
TextView display, display2;
And here’s how i am using the plus button
// Plus button setup
add.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
display.setText(""+counter);
Vibrator vibr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
vibr.vibrate (20);
You could create a class that holds the information related to your increment button:
and put objects of that class in a list – for example for 3 buttons: