checkbox,radioButton,togglebutton,seekbar属性

android:checked="true"

Set the initial state of the button, true is the selected state, false is the unselected state

Format the initial state in code

        CheckBox cb=findViewById(R.id.checkBox);
// Set whether the check box is selected
        cb.setChecked(false);

// Get the state of the checkbox
        boolean ischecked=cb.isChecked();

set monitor


 cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {

            }
        });

 The difference between radiobutton and checkbox

radiobutton cannot be clicked to become selected

radiobutton is a single-selection control, and checkbox is a multi-selection control

radiobutton defaults to a circular box in most cases

ToggleButton

seekbar:

setprogress(): set the current progress in the code

Attributes:

max : set the maximum progress

progress : set the current progress

 

set monitor

mseekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
        price=seekBar.getProgress();
        Toast.makeText(SelectActivity.this,"价格"+price,Toast.LENGTH_SHORT).show();

    }
});

Guess you like

Origin blog.csdn.net/m0_63911789/article/details/124460949