Do I need to create a different string for each activity?

0

I am doing an exercise in which I entered Fahrenheit degrees and I convert them to Celsius. On the second screen the result appears, but I want to put a textView that says "The result is" and I do not get it. Do I need to create another xml file or do I also need to pass as a parameter as well as pass the value that I got in the formula?

/* CODIGO JAVA DEL SEGUNDO ACTIVITY */

public class SecondActivity extends ActionBarActivity {

    TextView resultado;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);

        resultado= (TextView) findViewById(R.id.resultado);// Acá esta el texto 
                                                           //que dice el 
                                                           //resultado es, pero
                                                           //no aparece :/

        String valor=getIntent().getExtras().getString("clave");

        ((TextView)findViewById(R.id.resultado)).setText(valor);

    }
}

XML OF THE 2ND ACTIVITY:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              xmlns:app="http://schemas.android.com/apk/res-auto"
              xmlns:tools="http://schemas.android.com/tools"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:orientation="vertical"
              tools:context="com.example.brenda.celsius_a_farenheit.SecondActivity">


    <TextView
        android:id="@+id/resultado"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/resultado" />
</LinearLayout>

STRING XML

<resources>
    <string name="app_name"></string>
    <string name="Etiqueta_datos">Ingrese temperatura</string>
    <string name="Boton">Click para ver el resultado</string>
    <string name="resultado">El resultado es: </string>
</resources>
    
asked by Brenda Yanela Conzi 20.10.2017 в 22:21
source

1 answer

0

In this case the value of the TextView is in strings, you have to reference it in this way:

resultado.setText(getResources().getString(R.string.resultado)+" "+valor);

The other way, as you already commented, is concatenated, in this case it is not necessary that The value of the TextView is in values / strings:

resultado.setText("El resultado es: "+valor);
    
answered by 20.10.2017 в 23:04