• 4.4 我同意条款—CheckBox的isCheck属性


    4.4 我同意条款—CheckBoxisCheck属性

    目录

    4.4 我同意条款—CheckBoxisCheck属性... 1

    目标: 1

    方法: 1

    代码: 1

    : 4

     

    目标:只有同意了使用条款才能进入界面.

    方法:CheckBoxisCheck方法 ButtonseEnabled方法结合使用.

    代码:

    package edu.cquptzx.CheckBox;

     

    import android.app.Activity;

    import android.app.AlertDialog;

    import android.content.DialogInterface;

    import android.os.Bundle;

    import android.view.View;

    import android.widget.Button;

    import android.widget.CheckBox;

    import android.widget.TextView;

    import android.widget.Toast;

     

    public class CheckBoxActivity extends Activity

    {

        /** Called when the activity is first created. */

        private TextView tv;

        private CheckBox cb;

        private Button btn;

        @Override

        public void onCreate(Bundle savedInstanceState)

        {

            super.onCreate(savedInstanceState);

            setContentView(R.layout.main);

           

            //取得对象ID.

            tv = (TextView)findViewById(R.id.textView);

            cb = (CheckBox) findViewById(R.id.checkBox);

            btn = (Button) findViewById(R.id.button);

           

            //初始化按钮和选项状态

            cb.setChecked(false);

            btn.setEnabled(false);

           

            //为选项添加监听器

            cb.setOnClickListener(new CheckBox.OnClickListener()

                {

                  public void onClick(View v)

                  {  

                      //如果不同意条款,那么确定按钮不可选中.

                      if(cb.isChecked() == true)

                      {

                         btn.setEnabled(true);

                      }

                      else

                      {

                         btn.setEnabled(false);  

                         new AlertDialog.Builder(CheckBoxActivity.this)

                         .setTitle("注意")

                         .setMessage("只有同意了条款才能进入应用!")

                         .setPositiveButton("返回同意",

                             new DialogInterface.OnClickListener()

                             {                   

                                public void onClick(DialogInterface dialog, int which)

                                {

                                    tv.setText(getString(R.string.item).toString());

                                }

                             })

                         .setNegativeButton("我要退出",

                             new DialogInterface.OnClickListener()

                             {                   

                                public void onClick(DialogInterface dialog, int which)

                                {

                                    Toast.makeText(CheckBoxActivity.this, "退出应用中", Toast.LENGTH_LONG).show();

                                    finish();

                                }                       

                             })

                         .show();         

                        

                      }

                     

                  }  

                });

           

            btn.setOnClickListener(new Button.OnClickListener()

                {

                  public void onClick(View v)

                  {

                         tv.setText("您已经同意了条款,下面进入应用.");     

                         //doThings Next

                  }          

                });

        }  

    }

    效果:

    clip_image001

    clip_image002

    clip_image003

    clip_image004

    clip_image005

    For more questions , contacts me by :

    cquptzx@qq.com or  cquptzx@outlook.com

     

  • 相关阅读:
    面向切面编程AOP
    多线程:Monitor、synchronized、volatile
    约束布局ConstraintLayout
    【转】StackTraceElement获取方法调用栈的信息
    Java中的Type
    Android App 架构演变
    Java泛型
    web测试方法总结
    机器学习 损失函数
    深度学习 激活函数
  • 原文地址:https://www.cnblogs.com/xilifeng/p/2657060.html
Copyright © 2020-2023  润新知