1.layout代码
110 11 19 20 27 28 35 36
2.源代码
package com.example.text2;import android.os.Bundle;import android.util.Log;import android.accounts.Account;import android.accounts.OnAccountsUpdateListener;import android.app.Activity;import android.view.Menu;import android.widget.CheckBox;import android.widget.CompoundButton;import android.widget.CompoundButton.OnCheckedChangeListener;public class MainActivity extends Activity { private CheckBox CheckBox1; private CheckBox CheckBox2; private CheckBox CheckBox3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); CheckBox1 =(CheckBox) findViewById(R.id.checkBox1); CheckBox2 =(CheckBox) findViewById(R.id.checkBox2); CheckBox3 =(CheckBox) findViewById(R.id.checkBox3); CheckBox1.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { // TODO Auto-generated method stub if(arg1){ String text = CheckBox1.getText().toString(); Log.i("tag", text); } } }); CheckBox2.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { // TODO Auto-generated method stub if (arg1) { String text = CheckBox2.getText().toString(); Log.i("tag",text); } } }); CheckBox3.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton arg0, boolean arg1) { // TODO Auto-generated method stub if(arg1){ String text = CheckBox3.getText().toString(); Log.i("tag", text); } } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; }}
3.点击足球选项之后,logcat的效果
04-18 22:37:19.921: I/tag(1694): 足球