Display variable on screen using Android from TextViews

I have a little problem displaying the variable on the screen.

Now I have a tab. On the fourth tab there is a nested ActivityGroup that has a map inside it.

The problem is that the activity of this setContentView map setContentView set to R.layout.gps

I am trying to display the distance traveled on the ontop screen or next to the map to show how far the user has advanced.

I can get the text to display on the screen by creating a text view inside XML. However, using this method, I cannot bind it to the Double variable inside the action.

At the same time, if I create TextView t = new TextView(this) , it will not be displayed on the screen, since it will have installed content.

If anyone could shed light on this, it would be very helpful.

+4
source share
2 answers

Make sure that the TextView you want to use in res / layout / gps.xml has the following in it:

android:id="@+id/mytextview"

And then use Klaus code to find the TextView in your Java code:

TextView myTextView = (TextView) findViewById(R.id.mytextview); myTextView.setText("My double value is " + doubleValue);

+5
source

Suppose you have a TextView in your XML with the identifier mytextview.

Using:

 TextView myTextView = (TextView) findViewById(R.id.mytextview); 

to get a dynamic link to a TextView. Then you can use

 myTextView.setText("My double value is " + doubleValue); 

upgrade it while you go ahead.

0
source

Source: https://habr.com/ru/post/1342011/


All Articles