Hallo,
ich möchte gerne in einem Recyclerview Item den letzten Eintrag von jeweils 3 Array Listen ausgeben. In den folgenden Items natürlich die nächsten Einträge der 3 Listen usw.. Leider verstehe ich nicht wieso nicht alle Daten vom letzten Eintrag in einem Recyclerview Item ausgegeben werden sondern die Einträge verteilt werden auf die nächsten Recyclerviews. Wo könnte das Problem liegen?
Code
public class EntryAdapter extends RecyclerView.Adapter<EntryAdapter.EntryViewHolder> {
private List<Entry_Pagination> lagerhausEntries;
private List<Entry_Pagination> jetEntries;
private List<Entry_Pagination> shellEntries;
public EntryAdapter(List<Entry_Pagination> lagerhausEntries, List<Entry_Pagination> jetEntries, List<Entry_Pagination> shellEntries) {
this.lagerhausEntries = lagerhausEntries;
this.jetEntries = jetEntries;
this.shellEntries = shellEntries;
}
@NonNull
@Override
public EntryViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.entry_item_layout, parent, false);
return new EntryViewHolder(itemView);
}
@Override
public void onBindViewHolder(@NonNull EntryViewHolder holder, int position) {
// Determine which tankstelle (gas station) the entry belongs to
Entry_Pagination entry;
int itemViewType = getItemViewType(position);
if (itemViewType == 0) {
entry = lagerhausEntries.get(position);
holder.bindEntry("liezen_lagerhaus_tankstelle", entry);
} else if (itemViewType == 1) {
entry = jetEntries.get(position - lagerhausEntries.size());
holder.bindEntry("liezen_jet_tankstelle", entry);
} else {
entry = shellEntries.get(position - lagerhausEntries.size() - jetEntries.size());
holder.bindEntry("trautenfels_shell_tankstelle", entry);
}
}
@Override
public int getItemViewType(int position) {
if (position < lagerhausEntries.size()) {
return 0; // Lagerhaus Tankstelle
} else if (position < lagerhausEntries.size() + jetEntries.size()) {
return 1; // Jet Tankstelle
} else {
return 2; // Shell Tankstelle
}
}
@Override
public int getItemCount() {
// Total count is the sum of entries from all tankstellen
return lagerhausEntries.size() + jetEntries.size() + shellEntries.size();
}
public static class EntryViewHolder extends RecyclerView.ViewHolder {
private CardView cardView;
private TextView priceTextView;
private TextView fuelTypeTextView;
private TextView tankstelleTextView;
private TextView adresseTextView;
private TextView zeitTextView;
private TextView priceTextView2;
private TextView fuelTypeTextView2;
private TextView tankstelleTextView2;
private TextView adresseTextView2;
private TextView zeitTextView2;
private TextView priceTextView3;
private TextView fuelTypeTextView3;
private TextView tankstelleTextView3;
private TextView adresseTextView3;
private TextView zeitTextView3;
public EntryViewHolder(@NonNull View itemView) {
super(itemView);
cardView = itemView.findViewById(R.id.cv);
// Initialize views for Lagerhaus Tankstelle
priceTextView = itemView.findViewById(R.id.tvPreis);
fuelTypeTextView = itemView.findViewById(R.id.tvTreibstoff);
tankstelleTextView = itemView.findViewById(R.id.tvTankstelle);
adresseTextView = itemView.findViewById(R.id.tvAdresse);
zeitTextView = itemView.findViewById(R.id.tvZeit);
// Initialize views for Jet Tankstelle
priceTextView2 = itemView.findViewById(R.id.tvPreis2);
fuelTypeTextView2 = itemView.findViewById(R.id.tvTreibstoff2);
tankstelleTextView2 = itemView.findViewById(R.id.tvTankstelle2);
adresseTextView2 = itemView.findViewById(R.id.tvAdresse2);
zeitTextView2 = itemView.findViewById(R.id.tvZeit2);
// Initialize views for Shell Tankstelle
priceTextView3 = itemView.findViewById(R.id.tvPreis3);
fuelTypeTextView3 = itemView.findViewById(R.id.tvTreibstoff3);
tankstelleTextView3 = itemView.findViewById(R.id.tvTankstelle3);
adresseTextView3 = itemView.findViewById(R.id.tvAdresse3);
zeitTextView3 = itemView.findViewById(R.id.tvZeit3);
}
public void bindEntry(String tankstelleName, Entry_Pagination entry) {
// Bind entry data to views here
if (tankstelleName.equals("liezen_lagerhaus_tankstelle")) {
priceTextView.setText(entry.getPrice());
fuelTypeTextView.setText(entry.getFuelType());
tankstelleTextView.setText(entry.getStation());
adresseTextView.setText(entry.getAddress());
zeitTextView.setText(entry.getTime());
} else if (tankstelleName.equals("liezen_jet_tankstelle")) {
priceTextView2.setText(entry.getPrice());
fuelTypeTextView2.setText(entry.getFuelType());
tankstelleTextView2.setText(entry.getStation());
adresseTextView2.setText(entry.getAddress());
zeitTextView2.setText(entry.getTime());
} else if (tankstelleName.equals("trautenfels_shell_tankstelle")) {
priceTextView3.setText(entry.getPrice());
fuelTypeTextView3.setText(entry.getFuelType());
tankstelleTextView3.setText(entry.getStation());
adresseTextView3.setText(entry.getAddress());
zeitTextView3.setText(entry.getTime());
}
}
}
}
Alles anzeigen