日期:2014-05-20 浏览次数:20602 次
import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; public class ex02 extends Activity implements OnClickListener{ /** Called when the activity is first created. */ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); Button btn = (Button)findViewById(R.id.button); Button btn2 = (Button)findViewById(R.id.button2); btn.setOnClickListener(this); btn2.setOnClickListener(this); } public void onClick(View arg0){ switch(arg0.getId()){ case R.id.button: setTitle("this is OK button"); break; case R.id.button2: this.finish(); break; } } }
public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.main); Button btn = (Button)findViewById(R.id.button); Button btn2 = (Button)findViewById(R.id.button2); btn.setOnClickListener(this); btn2.setOnClickListener(this); }