SeekBar seekBar_y = findViewById(R.id.seekBar_y); seekBar_y.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { // 将进度值传递给 AsyncTask new SendDataTask().execute('y'+progress); } @Override public void onStartTrackingTouch(SeekBar seekBar) {} @Override public void onStopTrackingTouch(SeekBar seekBar) {} }); private class SendDataTask extends AsyncTask<Integer, Void, Void> { @Override protected Void doInBackground(Integer... params) { int progress = params[0]; // 将进度值发送到已连接的端口 out.println(progress); return null; } }改成发送不同位置对应的字符型数字
时间: 2024-03-09 09:46:55
浏览: 56
您可以在`onProgressC[han](https://geek.csdn.net/educolumn/0d22b54eaf6bcf967d9625e1679d00b4?spm=1055.2569.3001.10083)ged`方法中根据不同的位置来发送不同的字符型数字。例如,如果SeekBar的id为R.id.seekBar_x,您可以使用以下代码:
SeekBar seekBar_x = findViewById(R.id.seekBar_x);
seekBar_x.setOnSeekBarC[han](https://geek.csdn.net/educolumn/0d22b54eaf6bcf967d9625e1679d00b4?spm=1055.2569.3001.10083)geListener(new SeekBar.OnSeekBarC[han](https://geek.csdn.net/educolumn/0d22b54eaf6bcf967d9625e1679d00b4?spm=1055.2569.3001.10083)geListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 根据不同的位置发送不同的字符型数字
switch (seekBar.getId()) {
case R.id.seekBar_x:
new SendDataTask().execute('x' + [string](https://geek.csdn.net/edu/8802d631b97a4a6af1f4d0bbf8527465?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083).valueOf(progress));
break;
case R.id.seekBar_y:
new SendDataTask().execute('y' + [string](https://geek.csdn.net/edu/8802d631b97a4a6af1f4d0bbf8527465?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083).valueOf(progress));
break;
// 这里可以添加更多的位置
@Overr
```