RecyclerView (GridLayoutManager) does not display the data correctly (Android)

0

I'm trying to show some data in a recyclerview (gridLayoutManager). The data is loaded correctly, but when I scroll, it starts to paint badly.

Some data disappears, others that were not shown now are displayed. Imagining that the problem came by loading images, I commented the lines, which should only show a string.

calendario_item_list.xml

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_calendario"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

Calendar_item.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.android.volley.toolbox.NetworkImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/niv_flag"
        android:scaleType="center"/>

    <TextView
        android:id="@+id/country_name"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textSize="13sp"
        android:text="@string/app_name"
        android:textColor="@android:color/white"
        android:gravity="center"
        android:layout_below="@+id/niv_flag"
        android:paddingBottom="8dp"
        android:paddingTop="8dp"
        android:layout_alignParentBottom="true"
        android:background="@color/colorPrimary"/>

</RelativeLayout>

CalendarFragment.java public class CalendarFragment extends Fragment implements IVista {     private static final String ARG_COLUMN_COUNT="column-count";     private int mColumnCount = 3;     private OnListFragmentInteractionListener mListener;     Presenting presenter;     RecyclerView recyclerView;     CalendarRecyclerViewAdapter calendarRecyclerViewAdapter;     / **      * Mandatory empty constructor for the fragment manager to instantiate the      * fragment (e.g. upon screen orientation changes).      * /     public CalendarFragment () {     }

// TODO: Customize parameter initialization
@SuppressWarnings("unused")
public static CalendarioFragment newInstance(int columnCount) {
    CalendarioFragment fragment = new CalendarioFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_COLUMN_COUNT, columnCount);
    fragment.setArguments(args);
    return fragment;
}

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (getArguments() != null) {
        mColumnCount = getArguments().getInt(ARG_COLUMN_COUNT);
    }
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.calendario_item_list, container, false);
    Context context = view.getContext();
    recyclerView = (RecyclerView) view.findViewById(R.id.rv_calendario);
    presentador = new Presentador(this);
    presentador.solicitarDatosVolley();
    calendarioRecyclerViewAdapter = new CalendarioRecyclerViewAdapter(getActivity()
            ,presentador.getDatosArray(),mListener);

    recyclerView.setHasFixedSize(true);
    recyclerView.setAdapter(calendarioRecyclerViewAdapter);
    if (mColumnCount <= 1) {
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
    } else {
        recyclerView.setLayoutManager(new GridLayoutManager(context, mColumnCount));
    }
    return view;
}

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

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

@Override
public Context getApplicationContext() {
    return getActivity().getApplicationContext();
}

@Override
public void refrescarLista() {
    calendarioRecyclerViewAdapter.notifyDataSetChanged();
}

/**
 * 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 OnListFragmentInteractionListener {
    void onListFragmentInteraction(FivbCalendario item);
}

} CalendarRecyclerViewAdapter.java public class CalendarRecyclerViewAdapter extends RecyclerView.Adapter {

private final List<FivbCalendario> mValues;
private final OnListFragmentInteractionListener mListener;
private Context context;
private LayoutInflater inflater;

public CalendarioRecyclerViewAdapter(Context context,List<FivbCalendario> items, OnListFragmentInteractionListener listener) {
    mValues = items;
    mListener = listener;
    this.context=context;
    inflater=LayoutInflater.from(context);
}

@Override
public MiViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = inflater.inflate(R.layout.calendario_item, parent, false);
    MiViewHolder viewHolder = new MiViewHolder(view);
    return viewHolder;
}

@Override
public void onBindViewHolder(MiViewHolder holder, final int position) {

    holder.tvTitulo.setText(mValues.get(position).getTitulo());
   // ImageLoader netImageLoader= ControladorPeticiones.getInstance(context).getImageLoader();
    //holder.nivFlag.setImageUrl(Constantes.URL_GENERAL+holder.mItem.getPaisLink(), netImageLoader);
    holder.mView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mListener) {
                mListener.onListFragmentInteraction(mValues.get(position));
            }
        }
    });
}

@Override
public int getItemCount() {
    return mValues.size();
}

public class MiViewHolder extends RecyclerView.ViewHolder {
    public final View mView;
    public final TextView tvTitulo;
    public final NetworkImageView nivFlag;


    public MiViewHolder(View view) {
        super(view);
        mView = view;
        tvTitulo = (TextView) view.findViewById(R.id.country_name);
        nivFlag = (NetworkImageView) view.findViewById(R.id.niv_flag);
    }
}

}

    
asked by Rafa 29.04.2017 в 16:08
source

0 answers