I am new to android app. I am following a book to change the text dynamically, but it doesn't do what it is supposed to do. I have researched, but I couldn't find where is the problem. the app works find but don't change the text. I am stuck and I would really apreciate some help.
Java file:
public class ViewDVDActivity extends Activity {
TextView txtTituloDVD;
TextView txtAnyoDVD;
TextView txtActor1;
TextView txtActor2;
TextView txtResumenPelicula;
@Override
protected void onCreate ( Bundle saveInstanceState ) {
super.onCreate(saveInstanceState);
// asignacion layout
setContentView(R.layout.activity_viewdvd);
// obtención componentes
txtTituloDVD = (TextView) findViewById(R.id.tituloDVD);
txtAnyoDVD = (TextView) findViewById(R.id.anyoDVD);
txtActor1 = (TextView) findViewById(R.id.actor1);
txtActor2 = (TextView) findViewById(R.id.actor2);
txtResumenPelicula = (TextView) findViewById(R.id.resumenPelicula);
}
@Override
protected void onStart () {
super.onStart();
}
@Override
protected void onResume() {
super.onResume();
txtTituloDVD.setText("Matrix");
txtAnyoDVD.setText(String.format(getString(R.string.anyo_de_aparicion), 2014));
txtActor1.setText("Nelson Harris");
txtActor2.setText("Brian Eno");
String resumen = "En un lugar de la mancha de cuyo nombre no me acuerdo";
txtResumenPelicula.setText(resumen);
}
manifest.xml file:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.LocDVD">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewDVDActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
xml file: activity_viewdvd.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|top"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:text="TextView" />
<TextView
android:id="@+id/tituloDVD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Título del dvd"
android:layout_gravity="top|center_horizontal"
android:layout_marginTop="16dp"
android:textSize="22sp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Año"
android:textSize="15sp"
android:id="@+id/anyoDVD" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="18sp"
android:text="Actor 1"
android:id="@+id/actor1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="18sp"
android:text="Actor 2"
android:id="@+id/actor2" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:textSize="18sp"
android:text="Resumen"
android:minLines="5"
android:maxLines="15"
android:id="@+id/resumenPelicula" />
</LinearLayout>
String values:
<resources>
<string name="app_name">LocDVD</string>
<string name="anyo_de_aparicion">"Año de aparición : %d"</string>
<string name="titulo_de_la_pelicula">"Títlo de la película"</string>
<string name="anyo_de_aparicion_etiqueta">"Año de aparición"</string>
<string name="actores">"Actores"</string>
<string name="resumen">"Resumen"</string>
</resources>
I think you navigate to wrong activity
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.LocDVD">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".ViewDVDActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
because you have two luncher activity
if you want to show ViewDVDActivity
at first
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.LocDVD">
<activity android:name=".MainActivity">
</activity>
<activity android:name=".ViewDVDActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>