I want to display a message on the device screen.
The message is in System.out.println("Mensagem ")
;
How do I make a string
and print on the screen using a textView
?
I want to display a message on the device screen.
The message is in System.out.println("Mensagem ")
;
How do I make a string
and print on the screen using a textView
?
See if this helps.
String mensagem = "Mensagem";
TextView texto = (TextView)findViewById(R.id.id_do_texto_no_layout);
texto.setText(mensagem);
To "start" on the android screen, we use textview
in the layout.xml of activity
. You are trying to put in the screen of the android a text written "Message", but in format of string.
The last line texto.setText(mensagem);
is basically the same line System.out.println("Mensagem ");
but to display in android.
Aside 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();
Context of the application, if it is in an activity can use this
, fragment can use getActivity().getApplicationContext()
Message is self explanatory, it is the text you want to display
Duration is the time that the message will be on the screen, there are two constants with fixed times that 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