以下是用于在BluetoothChat Code中接收和显示数据的代码段。我想组合(连接)两个连续的值并将其显示为一个值。这可能吗?
BluetoothChat.java
// The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
String readMessage = new String(readBuf, 0, msg.arg1);
mConversationArrayAdapter.add(readMessage);
break;
}
}
}
答案 0 :(得分:0)
试试这个:它会将新项目添加到上一个列表的末尾。
mConversationArrayAdapter.addAll(readMessage);
答案 1 :(得分:0)
如果是每两条消息,这是一个解决方法:
// The Handler that gets information back from the BluetoothChatService
private final Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
int c = 0;
String s ="";
switch (msg.what) {
case MESSAGE_READ:
byte[] readBuf = (byte[]) msg.obj;
String readMessage = new String(readBuf, 0, msg.arg1);
c++;
s += readMessage;
if(c==2) {
mConversationArrayAdapter.add(readMessage);
c=0;
s=""
}
break;
}}}