1.新建两个button和一个testview,监听button,按下button1时,testview显示"LED setOn",并点亮LED,按下button2时testview显示"LED setOff",并关闭LED.
private Button button1;
private Button button2;
private TextView textView2;
@Override
protected void onCreate(Bundle savedInstanceState) {
button1 = (Button) findViewById(R.id.button1);
button2 = (Button) findViewById(R.id.button2);
textView2 = (TextView) findViewById(R.id.textView2);
button1.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
Log.v("asd", "button1");
String str = "LED setOn";
textView2.setText(str);
ledHalService.setOn(0);
}
});
button2.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
String str = "LED setOff";
textView2.setText(str);
ledHalService.setOff(1);
}
});
}