How to turn a system out to string?

Asked

Viewed 154 times

0

I want to display a message on the device screen.

The message is in System.out.println("Mensagem ");

how do I turn into a string and print on screen using a textView?

  • 3

    Either I don’t understand the problem or it doesn’t make sense. It would be better to [Dit] the question with your real code and show what you want. See how to make a [mcve].

2 answers

2

Apart from the option to put the message in a Textview, you can also use a "Toast"

Example

//Toast.makeText(<Context>, <Mensagem>, <Duração>).show();

Toast.makeText(this, "this is my Toast message!!! =)", Toast.LENGTH_SHORT).show();

Application context, if it is in an Activity you can use this, Fragment can use the getActivity().getApplicationContext()

Message is self explanatory, is the text you want to show

Duration is the time the message will be on the screen, there are two constants with fixed times you can use, if you want you can put the time in milliseconds

Toast.LENGTH_SHORT // Equivale a 2 segundos
Toast.LENGTH_LONG // Equivale a 3.5 segundos

2

See if this helps.

 String mensagem = "Mensagem";

 TextView texto = (TextView)findViewById(R.id.id_do_texto_no_layout);

 texto.setText(mensagem);

To "print" on the android screen, we use a textview in the.xml layout of activity. Vc is trying to put on the android screen a text written "Message", but in string format. The last line texto.setText(mensagem); is basically the same line System.out.println("Mensagem "); but to display on android.

  • Explain a little more about how your code helps answer the question

  • 1

    To "print" on the android screen, we use a textview. From what I understood of the doubt, he is trying to put on the android screen a text written "Message", but in string format.

  • 1

    The last line texto.setText(mensagem); is basically the same line System.out.println("Mensagem "); but to display on android.

  • Welcome to Sopt, enter this information in your reply, the more complete the best evaluated response it will be :D

  • Done! I believe I got a better answer... thanks for the observation points.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.