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;
import java.lang.reflect.Field;

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

        TableLayout t = (TableLayout)findViewById(R.id.counters);
        t.addView(new Counter(this, R.drawable.d2,   "d2"));
        t.addView(new Counter(this, R.drawable.d4,   "d4"));
        t.addView(new Counter(this, R.drawable.d8,   "d8"));
        t.addView(new Counter(this, R.drawable.d10,  "d10"));
        t.addView(new Counter(this, R.drawable.d12,  "d12"));
        t.addView(new Counter(this, R.drawable.d20,  "d20"));
        t.addView(new Counter(this, R.drawable.d100, "d100"));
        t.addView(new Counter(this, R.drawable.mul,  "mul"));
        t.addView(new Counter(this, R.drawable.mod,  "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);
            counter = (EditText)findViewById(R.id.counter);
        }
    }
}

@@ -382,40 +382,8 @@
 ter;
-%0Aimport java.lang.reflect.Field;
 %0A%0Apu
@@ -1749,53 +1749,679 @@
     
-counter = (EditText)findViewById(R.id.counter
+button.setOnClickListener(new ImageButton.OnClickListener()%0A            %7B%0A                public void onClick(View v)%0A                %7B%0A                    modValue(1);%0A                %7D%0A            %7D);%0A            counter = (EditText)findViewById(R.id.counter);%0A        %7D%0A%0A        public Integer getValue()%0A        %7B%0A            return new Integer(counter.getText().toString());%0A        %7D%0A%0A        public Integer setValue(Integer value)%0A        %7B%0A            counter.setText(value.toString());%0A            return getValue();%0A        %7D%0A%0A        public Integer modValue(Integer mod)%0A        %7B%0A            Integer value = getValue();%0A            return setValue(value + mod
 );%0A 

Implement control of the counters using the buttons.