如何编码字节来分离android中列表中的项目

时间:2017-09-13 10:44:08

标签: java android

我是android的新手,我有一个包含一些项目的encodeBytes。我想从encodeByte中分离所有项目并在spinner中显示。检查下面的代码,在数据变量中包含单个字符串中的所有项目,我想迭代每个项目并添加到列表

这是我的代码:

private void waitForResponse(InputStream mmInputStream, long timeout) throws IOException {
    int bytesAvailable;

    while (true) {
        bytesAvailable = mmInputStream.available();
        if (bytesAvailable > 0) {
            byte[] packetBytes = new byte[bytesAvailable];
            byte[] readBuffer = new byte[1024];
            mmInputStream.read(packetBytes);

            for (int i = 0; i < bytesAvailable; i++) {
                byte b = packetBytes[i];

                if (b == delimiter) {
                    byte[] encodedBytes = new byte[readBufferPosition];
                    System.arraycopy(readBuffer, 0, encodedBytes, 0, encodedBytes.length);
                    final String data = new String(encodedBytes, "US-ASCII");  **//Its show all item in single string,I want separate and each item add in list**
                    writeOutput("Received:" + data);                       
                    list.add(data);                        
                    return;
                } else {
                    readBuffer[readBufferPosition++] = b;
                }
            }
        }
    }
}

数据变量如下:

Security Check Corp_2 Tender Security Check Corp_1

我想在列表中这样:

Security Check
Corp_2                                                                     
Tender
Security Check
Corp_1

0 个答案:

没有答案