Ad

Sending String To 2 Textviews

- 1 answer

I have made an app that communicates via Bluetooth. It receives a string from a hardware device and displays the string to a text view. I want to know how to take that string and split it to send 1 half to one TextView and the other half to another TextView within the handler. At the moment it sends the string to 1 TextView as it is coded to.

mHandler = new Handler(){
        @SuppressLint("SetTextI18n")
        public void handleMessage(android.os.Message msg){
            if(msg.what == MESSAGE_READ){
                String readMessage = new String((byte[]) msg.obj,
                        StandardCharsets.UTF_8);
                textView.setText(readMessage);
            }
Ad

Answer

int middle = readMessage.lenght() / 2;
textView1.setText(readMessage.subString(0, middle));
textView2.setText(readMessage.subString(middle));
Ad
source: stackoverflow.com
Ad