常用控件的监控对应代码

Button

  buttonLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                display.setText(R.string.button1);
            }
        });

Switch

 aSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b==true){
                    display.setText("开");
                }else{
                    display.setText("关");
                }
            }
        });

RadioGroup

 radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int i) {
                if(i==R.id.radioButton1){
                    imageView.setImageResource(R.drawable.qq_pic_merged_1641112111742);
                }else{
                    imageView.setImageResource(R.drawable.qq_pic_merged_1641112091588);
                }
            }
        });

SeekBar

seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
                display.setText(String.valueOf(i));
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {

            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {

            }
        });

CheckBox

checkBox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                if(b){
                    yuwen=getString(R.string.checkbox1);
                }else{
                    yuwen="";
                }
                display.setText(yuwen+shuxue+yingyu);
            }
        });

RatingBar

 ratingBar.setOnRatingBarChangeListener(new RatingBar.OnRatingBarChangeListener() {
            @Override
            public void onRatingChanged(RatingBar ratingBar, float v, boolean b) {
                Toast toast= Toast.makeText(MainActivity.this,String.valueOf(v)+"星评价!",Toast.LENGTH_SHORT);
                toast.show();
            }
        });

 

上一篇:requests之https/超时处理


下一篇:腾讯防水墙实现验证码