package com.yanjun;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.TextView;

public class MainActivity extends Activity {
   /** Called when the activity is first created. */

  TextView textView;
  Button button;
  CheckBox checkBox;

  @Override
   public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    textView = (TextView) findViewById(R.id.textView1);
    button = (Button) findViewById(R.id.button1);
    checkBox = (CheckBox) findViewById(R.id.checkBox1);
     //checkBox.setChecked(true);默认已选中
         checkBox.setChecked( true);
    button.setEnabled( false);
    button.setOnClickListener( new OnClickListener() {

       public void onClick(View v) {
         // TODO Auto-generated method stub
         if (checkBox.isChecked()) {
          textView.setText( "点击按钮显示内容");
          textView.setTextColor(Color.BLUE);
        }
      }
    });
    checkBox.setOnClickListener( new OnClickListener() {

       public void onClick(View v) {
         // 判断选中状态
         if (checkBox.isChecked()) {
          button.setEnabled( true);
          textView.setText( "checkBox已选中,显示按钮");
          textView.setTextColor(Color.GREEN);
        } else {
          button.setEnabled( false);
          textView.setText( "checkBox没有选中,按钮变灰");
          textView.setTextColor(Color.RED);
        }
      }
    });

  }
}

更多相关文章

  1. Android组件 文本框(EditText)
  2. android RadioButton单选按钮的使用
  3. 购物车
  4. Android(安卓)仿苹果自定义Dialog
  5. 网络请求工具类HttpUtils
  6. Android:线性布局(LinearFrame)例子
  7. 过期Gallery取代方案horizontalscrollView之幻灯片效果
  8. Android(安卓)- SwitchButton开关按钮
  9. Android(安卓)获取系统自带相机的照片

随机推荐

  1. 使用FragmentTabHost时,tabwidget被framen
  2. Android(安卓)Asynchronous Http Client
  3. Android(安卓)移动安全知识技术全解(加固
  4. set androids action bar title color
  5. Android(安卓)异常:Immutable bitmap pass
  6. android 获取局域网内其他手机的ip
  7. Android下修改SeekBar样式
  8. Android(安卓)获取无线蓝牙MAC信息代码
  9. Android(安卓)搜索到的关键字改变颜色
  10. Android将HTML文本显示在webView控件中