zoukankan      html  css  js  c++  java
  • 每日总结

    今天学习的是Android的复选框

    运行效果图:

    实现代码:

    public class MainActivity extends AppCompatActivity implements View.OnClickListener,CompoundButton.OnCheckedChangeListener{
    
        private CheckBox cb_one;
        private CheckBox cb_two;
        private CheckBox cb_three;
        private Button btn_send;
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main);
    
            cb_one = (CheckBox) findViewById(R.id.cb_one);
            cb_two = (CheckBox) findViewById(R.id.cb_two);
            cb_three = (CheckBox) findViewById(R.id.cb_three);
            btn_send = (Button) findViewById(R.id.btn_send);
    
            cb_one.setOnCheckedChangeListener(this);
            cb_two.setOnCheckedChangeListener(this);
            cb_three.setOnCheckedChangeListener(this);
            btn_send.setOnClickListener(this);
    
        }
    
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
           if(compoundButton.isChecked()) Toast.makeText(this,compoundButton.getText().toString(),Toast.LENGTH_SHORT).show();
        }
    
        @Override
        public void onClick(View view) {
            String choose = "";
            if(cb_one.isChecked())choose += cb_one.getText().toString() + "";
            if(cb_two.isChecked())choose += cb_two.getText().toString() + "";
            if(cb_three.isChecked())choose += cb_three.getText().toString() + "";
            Toast.makeText(this,choose,Toast.LENGTH_SHORT).show();
        }
    }
  • 相关阅读:
    IBM Minus One(water)
    约瑟夫问题的循环链表实现
    双向链表(差不多)
    单向链表的建立,插入,删除(复习一下)
    找新朋友(欧拉函数)
    验证角谷猜想(hd1279)
    Wolf and Rabbit(gcd)
    Big Number(大数)
    字串数(高精度组合数)
    寻找素数对(hd1262)
  • 原文地址:https://www.cnblogs.com/lxywsx/p/14909334.html
Copyright © 2011-2022 走看看