Load the same RecyclerView with data from two or more SQLite tables

1

What I want is to make the data of the Cardview appear in a tabla1 and in the next CardView the data of the tabla2 . I tried to enter the data in the method onBindViewHolder but I have not succeeded. This is what I tried to do:

public void onBindViewHolder(final ViewHolder holder, int position) {

        holder._info.setText(tabla1.get(position).getInfo_estadistica());
        holder._seleccion.setText(tabla1.get(position).getSeleccion());
        holder.tituloCV.setText(tabla1.get(position).getTitulo_CV());
        holder.fondoCV.setImageResource(tabla1.get(position).getImagen_CV());
        holder._logo.setImageResource(tabla1.get(position).getLogo_equipo());
        holder._info.setText(tabla2.get(position).getInfoEq1_estadistica());
        holder._seleccion.setText(tabla2.get(position).getSeleccion_Eq1());
        holder.tituloCV.setText(tabla2.get(position).getTitulo_CV());
        holder.fondoCV.setImageResource(tabla2.get(position).getImagen_CV());
}

@Override
public int getItemCount() {
    //Obtener la cantidad de CardView que el Recycler va a cargar
    return size = (tabla1.size() + tabla2.size());
}

I only put these two methods considering that this is where the data is entered into views .

    
asked by Wandy Hernandez 21.08.2016 в 06:10
source

2 answers

1

Just as you have your code what you do is write all those data in each item, I think that what you need is an if you indicate if it is table 1 or table n, so the recyclerview will paint the data of table 1 in an item and the data of table n in item n and so on according to the number of items in your list.

example:

public void onBindViewHolder(final ViewHolder holder, int position) {

    if(tipoTabla == tabla1){
        holder._info.setText(tabla1.get(position).getInfo_estadistica());
        holder._seleccion.setText(tabla1.get(position).getSeleccion());
        holder.tituloCV.setText(tabla1.get(position).getTitulo_CV());
        holder.fondoCV.setImageResource(tabla1.get(position).getImagen_CV());
        holder._logo.setImageResource(tabla1.get(position).getLogo_equipo());
    }else if(tipoTabla == tablaN){
        holder._info.setText(tabla2.get(position).getInfoEq1_estadistica());
        holder._seleccion.setText(tabla2.get(position).getSeleccion_Eq1());
        holder.tituloCV.setText(tabla2.get(position).getTitulo_CV());
        holder.fondoCV.setImageResource(tabla2.get(position).getImagen_CV());
    }
}
    
answered by 22.08.2016 в 17:51
1

More or less something like that is what I'm doing, in the end I decided to save each table in a different Cardview using logically the same Recycler. And I'm solving the data problem by storing the two tables in a single list of data so I can manage it to my liking within the Recycler adapter.

Thanks anyway for answering!

    
answered by 24.08.2016 в 19:09