I have a problem and I can not solve it in any way.
I used to have a Activity
called MasInformacion
and did the following:
public class MasInformacion extends Activity {
private TextView editTextNombre ,editTextFecha, editTextZodiaco, editTextEdad, editTextDiasrestantes;
private Bundle extras;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mas_informacion);
editTextNombre = (TextView) findViewById(R.id.editTextNombre);
editTextFecha = (TextView) findViewById(R.id.editTextFecha);
editTextZodiaco = (TextView) findViewById(R.id.editTextZodiaco);
editTextEdad = (TextView) findViewById(R.id.editTextEdad);
editTextDiasrestantes = (TextView) findViewById(R.id.editTextDiasrestantes);
// Recupera en un Objeto Bundle si tiene valores que fueron pasados como
// parametro de una actividad.
extras = getIntent().getExtras();
if (estadoEditarPersona()) {
editTextNombre.setText(extras.getString("nombre"));
editTextFecha.setText(extras.getString("fecha"));
editTextZodiaco.setText(extras.getString("zodiaco"));
editTextEdad.setText(extras.getString("edad"));
editTextDiasrestantes.setText(extras.getString("diasrestantes"));
}
}
/// comprueba el estado de EditarPersona
public boolean estadoEditarPersona() {
// Si extras es diferente a null es porque tiene valores. En este caso
// es porque se quiere editar una persona.
if (extras != null) {
return true;
} else {
return false;
}
}
}
And since MainActivity
public void masInformacion(int p_id){
Persona persona;
try{
persona = baseDatos.getPersona(p_id);
// Se dirige a la actividad MasInformacion
Intent actividad_editarPersona = new Intent(this, MasInformacion.class);
// Carga los datos para mostrar en MasInformacion
actividad_editarPersona.putExtra("id", p_id);
actividad_editarPersona.putExtra("nombre", persona.getNombre());
actividad_editarPersona.putExtra("fecha", persona.getFecha());
actividad_editarPersona.putExtra("zodiaco", persona.getZodiaco());
actividad_editarPersona.putExtra("edad", persona.getEdad());
actividad_editarPersona.putExtra("diasrestantes", persona.getDiasrestantes());
startActivityForResult(actividad_editarPersona, CODIGO_RESULT_EDITAR_PERSONA);
}catch (Exception e){
Toast.makeText(getApplicationContext(), (getResources().getString(R.string.error_mostrarinformacion)), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}finally{
baseDatos.cerrar();
}
}
Using the method like this:
masInformacion((int)info.id);
And everything worked perfectly. But now I have changed that Activity
for a DialogFragment
, this:
public class MyDialogFragment extends DialogFragment {
private TextView editTextNombre ,editTextFecha, editTextZodiaco, editTextEdad, editTextDiasrestantes;
Bundle extras;
static MyDialogFragment newInstance() {
return new MyDialogFragment();
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.mas_informacion, container, false);
editTextNombre = (TextView) view.findViewById(R.id.editTextNombre);
editTextFecha = (TextView) view.findViewById(R.id.editTextFecha);
editTextZodiaco = (TextView) view.findViewById(R.id.editTextZodiaco);
editTextEdad = (TextView) view.findViewById(R.id.editTextEdad);
editTextDiasrestantes = (TextView) view.findViewById(R.id.editTextDiasrestantes);
// Recupera en un Objeto Bundle si tiene valores que fueron pasados como
// parametro de una actividad.
Bundle extras = getActivity().getIntent().getExtras();
if (estadoEditarPersona()) {
editTextNombre.setText(extras.getString("nombre"));
editTextFecha.setText(extras.getString("fecha"));
editTextZodiaco.setText(extras.getString("zodiaco"));
editTextEdad.setText(extras.getString("edad"));
editTextDiasrestantes.setText(extras.getString("diasrestantes"));
}
return view;
}
/// comprueba el estado de EditarPersona
public boolean estadoEditarPersona() {
// Si extras es diferente a null es porque tiene valores. En este caso
// es porque se quiere editar una persona.
if (extras != null) {
return true;
} else {
return false;
}
}
}
And the problem is now, I do not know how to modify MainActivity
correctly, I do the following but it does not work, since it does not read the information of my Sqlite
:
void showDialog() {
FragmentManager fm = getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment prev = fm.findFragmentByTag("dialog");
if (prev != null) {
ft.remove(prev);
}
ft.addToBackStack(null);
masInformacion((int)info.id);
DialogFragment newFragment = MyDialogFragment.newInstance();
newFragment.show(ft, "tag");
}
public void masInformacion(int p_id){
Persona persona;
try{
persona = baseDatos.getPersona(p_id);
// Se dirige a la actividad MasInformacion
Intent actividad_editarPersona = new Intent(this, MyDialogFragment.class);
// Carga los datos para mostrar en MasInformacion
actividad_editarPersona.putExtra("id", p_id);
actividad_editarPersona.putExtra("nombre", persona.getNombre());
actividad_editarPersona.putExtra("fecha", persona.getFecha());
actividad_editarPersona.putExtra("zodiaco", persona.getZodiaco());
actividad_editarPersona.putExtra("edad", persona.getEdad());
actividad_editarPersona.putExtra("diasrestantes", persona.getDiasrestantes());
startActivityForResult(actividad_editarPersona, CODIGO_RESULT_EDITAR_PERSONA);
}catch (Exception e){
Toast.makeText(getApplicationContext(), (getResources().getString(R.string.error_mostrarinformacion)), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}finally{
baseDatos.cerrar();
}
}
And I use the method like this: showDialog();
The only thing I get this way is to open my DialogFragment
but without reading the data of Sqlite
and also with this error in logcat
android.content.ActivityNotFoundException: Unable to find explicit activity class {anotherintent.dos / anotherinvent.dos.MyDialogFragment}; have you declared this activity in your AndroidManifest.xml?