package au.id.swords.third;

import android.app.Activity;
import android.os.Bundle;
import android.content.Context;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TableRow;
import android.widget.TableLayout;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.LayoutInflater;

public class ThirdActivity extends Activity
{
    Counter[] dice;
    Counter mul;
    Counter mod;

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

        dice = new Counter[7];
        dice[0] = new Counter(this, R.drawable.d2,   "d2");
        dice[1] = new Counter(this, R.drawable.d4,   "d4");
        dice[2] = new Counter(this, R.drawable.d8,   "d8");
        dice[3] = new Counter(this, R.drawable.d10,  "d10");
        dice[4] = new Counter(this, R.drawable.d12,  "d12");
        dice[5] = new Counter(this, R.drawable.d20,  "d20");
        dice[6] = new Counter(this, R.drawable.d100, "d100");
        mul  = new Counter(this, R.drawable.mul,  "mul");
        mod  = new Counter(this, R.drawable.mod,  "mod");

        TableLayout t = (TableLayout)findViewById(R.id.counters);
        for(Counter c: dice)
            t.addView(c);
        t.addView(mul);
        t.addView(mod);
    }

    private class Counter extends TableRow
    {
        ImageButton button;
        EditText counter;

        public Counter(Context ctx, int image, String name)
        {
            super(ctx);

            LayoutInflater li;
            li = (LayoutInflater)ctx.getSystemService(ctx.LAYOUT_INFLATER_SERVICE);
            li.inflate(R.layout.counter, this);

            button = (ImageButton)findViewById(R.id.button);
            button.setImageResource(image);
            button.setOnClickListener(new ImageButton.OnClickListener()
            {
                public void onClick(View v)
                {
                    modValue(1);
                }
            });
            counter = (EditText)findViewById(R.id.counter);
        }

        public Integer getValue()
        {
            return new Integer(counter.getText().toString());
        }

        public Integer setValue(Integer value)
        {
            counter.setText(value.toString());
            return getValue();
        }

        public Integer modValue(Integer mod)
        {
            Integer value = getValue();
            return setValue(value + mod);
        }
    }
}

@@ -169,24 +169,54 @@
 t.EditText;%0A
+import android.widget.Button;%0A
 import andro
@@ -230,32 +230,32 @@
 et.ImageButton;%0A
-
 import android.w
@@ -1458,24 +1458,527 @@
 ddView(mod);
+%0A%0A        Button reset = (Button)findViewById(R.id.reset);%0A        reset.setOnClickListener(new Button.OnClickListener()%0A        %7B%0A            public void onClick(View v)%0A            %7B%0A                resetCounters();%0A            %7D%0A        %7D);%0A    %7D%0A%0A    private String describeConfig()%0A    %7B%0A        return %22%22;%0A    %7D%0A%0A    private void roll()%0A    %7B%0A    %7D%0A%0A    private void resetCounters()%0A    %7B%0A        for(Counter c: dice)%0A            c.resetValue();%0A        mul.resetValue();%0A        mod.resetValue();
 %0A    %7D%0A%0A    
@@ -2940,32 +2940,32 @@
 ue.toString());%0A
-
             retu
@@ -2982,32 +2982,111 @@
 e();%0A        %7D%0A%0A
+        public void resetValue()%0A        %7B%0A            setValue(0);%0A        %7D%0A%0A
         public I

Add the resetCounters() method.