Im trying to move from one screen to the other using buttons, i CAN move from main to secondary but when trying to get back from the second screen i get an error message "unfortunately, app has stopped".
Note: I will have a 3rd layout/activity so i will copy the solution to this 3rd option.
Im new in android and wonder if you can provide a better approach to what im doing (activities ARE declared in manifest, actually when using the 2nd screen as main, it goes FINE to the 1st screen (as 2nd option) BUT when trying to get back to 2nd screen it gave me the error again), thx in advance!!:
package com.example.citas.medicas; import android.os.Bundle; import android.app.Activity; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class Citas_Medicas extends Activity { private Button btnIraRegistrarPaciente; private Button btnIraRegistrarDoctor; private Button btnIraRegistrarCita; private Button btnIraReportePacientes; private Button btnIraReporteHistorialCitas; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_citas__medicas); btnIraRegistrarPaciente = (Button)findViewById(R.id.btnIraRegistrarPaciente); btnIraRegistrarDoctor = (Button)findViewById(R.id.btnIraRegistrarDoctor); btnIraRegistrarCita = (Button)findViewById(R.id.btnIraRegistrarCita); btnIraReportePacientes = (Button)findViewById(R.id.btnIraReportePacientes); btnIraReporteHistorialCitas = (Button)findViewById(R.id.btnIraReporteHistorialCitas); } public void onStart() { super.onStart(); btnIraRegistrarPaciente.setOnClickListener(new OnClickListener() { public void onClick(View component) { setContentView(R.layout.registrarpaciente); } } ); } }
Here is the secondary java (not sure if the onStart is fine):
package com.example.citas.medicas; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; public class Registrar_Paciente extends Activity implements OnClickListener { private Button btnRegistrarPaciente; private Button btnVolverMenuPrincipal1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.registrarpaciente); btnRegistrarPaciente = (Button)findViewById(R.id.btnRegistrarPaciente); btnVolverMenuPrincipal1 = (Button)findViewById(R.id.btnVolverMenuPrincipal1); btnRegistrarPaciente.setOnClickListener(this); btnVolverMenuPrincipal1.setOnClickListener(this); } public void onStart() { super.onStart(); btnRegistrarPaciente.setOnClickListener( new OnClickListener() { public void onClick(View component) { setContentView(R.layout.registrarpaciente); } } ); btnVolverMenuPrincipal1.setOnClickListener( new OnClickListener() { public void onClick(View component) { setContentView(R.layout.activity_citas__medicas); //Intent intent = new Intent(Registrar_Paciente.this, Citas_Medicas.class); //startActivity(intent); } } ); } }