Я пытаюсь запустить действие в моем адаптере, но мне кажется, что я получаю ошибку на другом адаптере.
java.lang.ClassCastException: com.lim.fiture.fiture.models.ProgramTracker cannot be cast to com.lim.fiture.fiture.models.ProgramExercise
точки ошибки намой DayExerciseAdapter
, который содержит только две вещи;Упражнение имя и упражнениеReps.
Это мой DayExerciseAdapter , здесь ошибка
public class DayExerciseAdapter extends RecyclerView.Adapter<DayExerciseAdapter.ViewHolder> {
private Context context;
private ArrayList<ProgramExercise> programExercises;
public DayExerciseAdapter(Context context, ArrayList<ProgramExercise> programExercises) {
this.context = context;
this.programExercises = programExercises;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.day_exercise_layout_item, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
holder.exerciseName.setText(programExercises.get(position).getExerciseName().toUpperCase());
holder.exerciseReps.setText(String.valueOf(programExercises.get(position).getReps()));
}
@Override
public int getItemCount() {
return programExercises.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView exerciseName, exerciseReps, doneTxt;
public ViewHolder(View itemView) {
super(itemView);
exerciseName = itemView.findViewById(R.id.exerciseName);
exerciseReps = itemView.findViewById(R.id.exerciseReps);
doneTxt = itemView.findViewById(R.id.doneTxt);
}
}
}
Это то место, откуда я начинаюнамерение моей деятельности
public class UserProgramWeekAdapter extends RecyclerView.Adapter<UserProgramWeekAdapter.ViewHolder> {
private Context context;
private ArrayList<ProgramTrackerWrapper> programTrackers;
public UserProgramWeekAdapter(Context context, ArrayList<ProgramTrackerWrapper> programTrackers) {
this.context = context;
this.programTrackers = programTrackers;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.activity_user_program_week_adapter, parent, false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(UserProgramWeekAdapter.ViewHolder holder, int position) {
Log.d("UserProgramWeekAdapter", "Day: " + programTrackers.get(position).getDay());
Log.d("UserProgramWeekAdapter", "Size: " + programTrackers.get(position).getProgramTrackers().size());
holder.dayTxt.setText(programTrackers.get(position).getDay());
holder.numberofExercises.setText(programTrackers.get(position).getProgramTrackers().size() + " exercise/s");
boolean isFinished = false;
final int sublistSize = programTrackers.get(position).getProgramTrackers().size();
for (int i = 0; i < sublistSize; i++) {
if (programTrackers.get(position).getProgramTrackers().get(i).isProgramExerciseFinished()) {
isFinished = true;
}
@Override
public int getItemCount() {
return programTrackers.size();
}
public class ViewHolder extends RecyclerView.ViewHolder {
TextView dayTxt, exerciseCompleted, numberofExercises;
CardView dayCard;
public ViewHolder(View itemView) {
super(itemView);
dayTxt = itemView.findViewById(R.id.dayTxt);
exerciseCompleted = itemView.findViewById(R.id.exerciseCompleted);
numberofExercises = itemView.findViewById(R.id.numberofExercises);
dayCard = itemView.findViewById(R.id.dayCard);
dayCard.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
((StartProgramActivity) context).setWeekExercisesData(getAdapterPosition());
ArrayList<ProgramTracker> programTrackerWrappers = ((StartProgramActivity) context).getDayOfWeekExercises();
if (programTrackerWrappers.size() > 0) {
context.startActivity(new Intent(context.getApplicationContext(), DayExerciseActivity.class).putExtra("programExercises", programTrackerWrappers));
}else {
CustomToast customToast = new CustomToast(context);
customToast.setTextColor(context.getResources().getColor(R.color.white));
customToast.setBackground(context.getResources().getColor(R.color.color_2));
customToast.showErrorToast("No exercises for this day.");
}
}
});
}
}
Что я получаю: // ошибка //