buttonSwitchSeekBar

mac2024-05-16  27

Button button1 = (Button) findViewById(R.id.button3); button1.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(MainFirstActivity.this, "你点了我", Toast.LENGTH_SHORT).show(); } }); Switch switch1 = (Switch) findViewById(R.id.switch2); switch1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked){ //Todo Toast.makeText(MainFirstActivity.this, "你打开了开关", Toast.LENGTH_SHORT).show(); Switch switch1 = (Switch) findViewById(R.id.switch2); switch1.setText("我开了"); }else { //Todo Toast.makeText(MainFirstActivity.this, "你关闭了开关", Toast.LENGTH_SHORT).show(); Switch switch1 = (Switch) findViewById(R.id.switch2); switch1.setText("我关了"); } } }); SeekBar seekBar = (SeekBar)findViewById(R.id.seekBar); final TextView tv1= (TextView)findViewById(R.id.textView); seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { tv1.setText("当前进度值:" + progress + " / 100 "); } @Override public void onStartTrackingTouch(SeekBar seekBar) { Toast.makeText(MainFirstActivity.this, "开始滑动", Toast.LENGTH_SHORT).show(); } @Override public void onStopTrackingTouch(SeekBar seekBar) { //Toast.makeText(mContext, "放开SeekBar", Toast.LENGTH_SHORT).show(); Toast.makeText(MainFirstActivity.this, "结束滑动", Toast.LENGTH_SHORT).show(); } });

 

最新回复(0)