De Fragment a Activity

11 views
Skip to first unread message

Ismael

unread,
May 21, 2017, 10:10:05 AM5/21/17
to desarrolladores-android
Hola, he empezado con adroid estudio, y quería hacer un navigation drawer activity. Ya tengo hecho mi Fragmentos con mi botón, pero no se como coger ese botón del fragmentos y darle la orden de que me pase a una actividad. He buscado por todos lados pero nada me funciona gracias.

Gabriel Pozo

unread,
May 21, 2017, 11:27:07 AM5/21/17
to desarrolladores-android

Te referís a algo así?  http://stackoverflow.com/a/27716825
Si no, deberías enviar el código,  y explicar mejor cual es la finalidad o funcionalidad a implementar.


El dom., 21 de may. de 2017 11:10, Ismael <ismaelme...@gmail.com> escribió:
Hola, he empezado con adroid estudio, y quería hacer un navigation drawer activity. Ya tengo hecho mi Fragmentos con mi botón, pero no se como coger ese botón del fragmentos y darle la orden de que me pase a una actividad. He buscado por todos lados pero nada me funciona gracias.

--
Para participar es necesario que leas detenidamente las normas del grupo: https://goo.gl/xeTRQm
---
Has recibido este mensaje porque estás suscrito al grupo "desarrolladores-android" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a desarrolladores-a...@googlegroups.com.
Para publicar una entrada en este grupo, envía un correo electrónico a desarrollad...@googlegroups.com.
Visita este grupo en https://groups.google.com/group/desarrolladores-android.
Para ver este debate en la Web, visita https://groups.google.com/d/msgid/desarrolladores-android/036a36f3-5aae-459e-b3b4-ada1fa69a153%40googlegroups.com.
Para obtener más opciones, visita https://groups.google.com/d/optout.

Ismael

unread,
May 21, 2017, 1:33:36 PM5/21/17
to desarrollad...@googlegroups.com
package app.ismael.com.myapplication;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;


/**
* A simple {@link Fragment} subclass.
* Activities that contain this fragment must implement the
* {@link FragmentCuantoSabes.OnFragmentInteractionListener} interface
* to handle interaction events.
*/
public class FragmentCuantoSabes extends Fragment {
Button btnfr1;

private OnFragmentInteractionListener mListener;



public FragmentCuantoSabes(){}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {

View view = inflater.inflate(R.layout.fragment_fragment_cuanto_sabes, container, false);

Button btnfr1 = (Button)view.findViewById(R.id.btnfr1);
btnfr1.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v){
switch(v.getId()){

case R.id.
btnfr1:
Intent intent1 =
new Intent(getActivity(), Main1Activity.class);
startActivity(intent1);
//Edited here
break;


}
}
});

return view;
}

// TODO: Rename method, update argument and hook method into UI event
public void onButtonPressed(Uri uri) {
if (mListener != null) {
mListener.onFragmentInteraction(uri);
}

}

@Override
public void onAttach(Context context) {
super.onAttach(context);
if (context instanceof OnFragmentInteractionListener) {
mListener = (OnFragmentInteractionListener) context;
}
else {
throw new RuntimeException(context.toString()
+
" must implement OnFragmentInteractionListener");
}
}

@Override
public void onDetach() {
super.onDetach();
mListener = null;
}

/**
* This interface must be implemented by activities that contain this
* fragment to allow an interaction in this fragment to be communicated
* to the activity and potentially other fragments contained in that
* activity.
* <p>
* See the Android Training lesson <a href=
* "http://developer.android.com/training/basics/fragments/communicating.html"
* >Communicating with Other Fragments</a> for more information.
*/
public interface OnFragmentInteractionListener {
// TODO: Update argument type and name
void onFragmentInteraction(Uri uri);
}

}




Este es mi fragment con las indicaciones para que mi boton funcione,pero no me funciona, al hacer click al boton se me crashea la app

Ismael

unread,
May 21, 2017, 2:00:50 PM5/21/17
to desarrolladores-android
Arreglado, era un problema de otra actividad que estaba mal. De todas formas gracias

Gabriel Pozo

unread,
May 21, 2017, 6:27:51 PM5/21/17
to desarrolladores-android

Que bueno que lo hayas solucionado,  estaría mejor si comentas cual era el problema 😉
Saludos


El dom., 21 de may. de 2017 15:00, Ismael <ismaelme...@gmail.com> escribió:
Arreglado, era un problema de otra actividad que estaba mal. De todas formas gracias

--
Para participar es necesario que leas detenidamente las normas del grupo: https://goo.gl/xeTRQm
---
Has recibido este mensaje porque estás suscrito al grupo "desarrolladores-android" de Grupos de Google.
Para cancelar la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a desarrolladores-a...@googlegroups.com.
Para publicar una entrada en este grupo, envía un correo electrónico a desarrollad...@googlegroups.com.
Visita este grupo en https://groups.google.com/group/desarrolladores-android.
Reply all
Reply to author
Forward
0 new messages