Red > Green > Refactor > Red

cycle is based on desire

Button event (without anonymous class) ; Android

memo

ボタンを押下したときにイベントを発火する

匿名クラスを使わない

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Button;

public class MainActivity extends Activity implements View.OnClickListener {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    Button saveButton = (Button)findViewById(R.id.SaveEditButton);
    saveButton.setOnClickListener(this);
  }

  @Override
  public void onClick(View view) {
    EditText editText = (EditText)findViewById(R.id.MainEdit);
    editText.setText("foo");
  }
}

参考元

http://developer.android.com/guide/topics/ui/ui-events.html