K
K
Konstantin Malyarov2016-01-24 21:04:47
Java
Konstantin Malyarov, 2016-01-24 21:04:47

New message to new textView?

textViewMessage = new TextView(this);

private class SetScrollViewMessage implements Runnable {
        @Override
        public void run() {
            try {
                InputStream inputStream = socket.getInputStream();
                DataInputStream dataInputStream = new DataInputStream(inputStream);
                if(dataInputStream != null){
                    final String stringMessage = dataInputStream.readUTF();
                    runOnUiThread(new Runnable() {
                        @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
                        @Override
                        public void run() {
                            while (true){
                                textViewMessage.setText(stringMessage);
                                textViewMessage.setBackgroundResource(R.color.colorPrimaryDark);
                                textViewMessage.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT));
                                linearLayoutMessage.addView(textViewMessage);
                            }
                        }
                    });
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }


I made it so that the new incoming message creates a textView and draws the text there. With one textView it rolls. What if two or more messages are returned?

PS I want to implement something similar to incoming and outgoing messages (SMS).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
IceJOKER, 2016-01-24
@IceJOKER

ListView is what you need

T
Tiberal, 2016-01-25
@Tiberal

Do not use archaisms there! RecyclerView is what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question