能将发送数字改成发送字符型数字吗
时间: 2024-03-09 21:46:30 浏览: 48
当然可以。你可以将SeekBar的当前值转换为字符型数字并发送给所连接的端口。具体实现可以按照以下步骤进行:
1. 在SeekBar的监听器中,将SeekBar的当前值转换为字符型数字并发送给所连接的端口:
```
SeekBar seekBar = findViewById(R.id.seekBar);
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// 将SeekBar的当前值转换为字符型数字并发送给所连接的端口
out.println(String.valueOf(progress));
}
//...
});
```
2. 在ConnectTask类中,将out对象定义为成员变量,以便在SeekBar的监听器中使用:
```
private class ConnectTask extends AsyncTask<String, Void, Void> {
private PrintWriter out;
@Override
protected Void doInBackground(String... params) {
String ip = params[0];
int port = Integer.parseInt(params[1]);
try {
socket = new Socket(ip, port);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
```
阅读全文