2

Estoy tratando de desarrollar una aplicación que parezca un feed de noticias donde la información se obtiene de un json que esta en un host, desde ahí yo puedo agregar y modificar los datos, la información se muestra en un cardview el problema es que yo quiero que al hacer click sobre uno de ellos se abra el item y muestre la información completa, por el momento trato de hacerlo con un DialogFragment de esta manera

MainActivity

recyclerView.addOnItemTouchListener(
  new MyRecyclerAdapter.RecyclerTouchListener(
    getApplicationContext(), recyclerView, new MyRecyclerAdapter.ClickListener() {
@Override
public void onClick(View view, int position) {
    Bundle bundle = new Bundle();
    bundle.putSerializable("images", datos);
    bundle.putInt("position", position);

    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    Detalles newFragment = Detalles.newInstance();
    newFragment.setArguments(bundle);
    newFragment.show(ft, "slideshow");
}

Detalles.java

public class Detalles extends DialogFragment{
    private String TAG = Detalles.class.getSimpleName();
    private ArrayList<NewsFeed> datos;
    private TextView tituloon, notoon;

    private View viewPager;

     private MyViewPagerAdapter myViewPagerAdapter;
        private int selectedPosition = 0;
    static Detalles newInstance() {
        Detalles f = new Detalles();
        return f;
    }

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

        View v = inflater.inflate(R.layout.detalles_completo, container, false);
        tituln = (TextView) v.findViewById(R.id.titulon);
        notlnn = (TextView) v.findViewById(R.id.noton);
        datos = (ArrayList<NewsFeed>) getArguments().getSerializable("images");
         myViewPagerAdapter = new MyViewPagerAdapter();

        selectedPosition = getArguments().getInt("position");

        return v;
    }
    private void displayMetaInfo(int position) {

        NewsFeed image = datos.get(position);
        tituln.setText(image.getFeedName());
        notlnn.setText(image.getContent());
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    public class MyViewPagerAdapter extends PagerAdapter {

        private LayoutInflater layoutInflater;

        public MyViewPagerAdapter() {
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {

            layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View view = layoutInflater.inflate(R.layout.detalles_completo, container, false);

            NewsFeed image = datos.get(position);

            tituln.setText(image.getFeedName());

            container.addView(view);

            return view;
        }
        @Override
        public int getCount() {
            return datos.size();
        }
        @Override
        public boolean isViewFromObject(View view, Object obj) {
            return view == ((View) obj);
        }
        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);

        }
    }
}

Con esto al hacer click en el cardview logro que se abra el DialogFragment, pero solo muestra el texto que está por defecto en el layout, no funciona el GetFeedname. Sé que el código tiene un montón de errores y es porque trato de implementar un ejemplo que encontré por ahí, espero su consejo.

1 respuesta 1

0

Al parecer olvidaste invocar el metodo displayMetaInfo desde onCreateView. Con eso mostrara los valores.

2
  • Lo intente pero tampoco funciona, al dar click se cierra la aplicación
    – SpaceSpace
    el 11 nov. 2016 a las 0:37
  • 1
    @SpaceSpace La aplicación se cierra por algún error? Si es así me podrías mostrar el log? el 11 nov. 2016 a las 0:54

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.