I have ActivityCourses and ActivityNewCourse. ActivityCourses include a list (recyclerview) of custom courses that user make, and ActivityNewCourse obviously is the activity where the user makes those custom courses.
ActivityNewCourse contains primitive data (course name and number of holes) those are the data, which I pass to ActivityCourses, and make new item there in its recyclerview (so the new items name is that course name which is passed from ActivityNewCourse).
The problem I have is that ActivityNewCourse also contains recyclerview, and that contains obviously unique items. I need to get all those items, from ActivityNewCourse, and get them STORED (not shown) in that same item, where I send primitive data in ActivityCourses.
I've tried to use interface in my NewCourseAdapter, to pass those items from ActivityNewCourse recyclerview, to my ActivityCourses item, but the problem is that I need all of them items, not just 1. and also that button "Save Course" which user clicks to obviously save all the data from ActivityNewCourse, is outside of the recyclerview, where those items are located.
HERE IS MY NEW COURSE ADAPTER
public class NewCourseAdapter extends RecyclerView.Adapter<NewCourseAdapter.NewCourseViewHolder> {
private ArrayList<NewCourseItem> mNewCourseList;
private OnItemClickListener mListener;
public interface OnItemClickListener {
void onMinusClick(int position);
void onPlusClick(int position);
}
public void setOnItemClickListener(OnItemClickListener listener) {
mListener = listener;
}
public static class NewCourseViewHolder extends RecyclerView.ViewHolder {
public TextView mTextView1, mTextView2;
public ImageView mImageView1, mImageView2;
public NewCourseViewHolder(@NonNull View itemView, final OnItemClickListener listener) {
super(itemView);
mTextView1 = itemView.findViewById(R.id.hole_number);
mTextView2 = itemView.findViewById(R.id.par_number);
mImageView1 = itemView.findViewById(R.id.item_minus_btn);
mImageView2 = itemView.findViewById(R.id.item_plus_btn);
mImageView1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.onMinusClick(position);
}
}
}
});
mImageView2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (listener != null) {
int position = getAdapterPosition();
if (position != RecyclerView.NO_POSITION) {
listener.onPlusClick(position);
}
}
}
});
}
}
public NewCourseAdapter(ArrayList<NewCourseItem> newCourseList) {
mNewCourseList = newCourseList;
}
@NonNull
@Override
public NewCourseViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.new_course_item, parent, false);
NewCourseViewHolder evh = new NewCourseViewHolder(v, mListener);
return evh;
}
@Override
public void onBindViewHolder(@NonNull NewCourseViewHolder holder, int position) {
NewCourseItem currentItem = mNewCourseList.get(position);
holder.mTextView1.setText(currentItem.getText1());
holder.mTextView2.setText(currentItem.getText2());
holder.mImageView1.setImageResource(currentItem.getImageMinus());
holder.mImageView2.setImageResource(currentItem.getImagePlus());
}
@Override
public int getItemCount() {
return mNewCourseList.size();
}
}
HERES HOW I PASS PRIMITIVE DATA FROM ACTIVITYNEWCOURSE TO ACTIVITYCOURSES
save.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
courseName = findViewById(R.id.course_name_input);
number = findViewById(R.id.number_of_holes_number);
String intentCourseName = courseName.getText().toString().trim();
String holeNumber = number.getText().toString().trim();
Intent intent = new Intent(ActivityNewCourse.this, ActivityCourses.class);
intent.putExtra("COURSENAME", intentCourseName);
intent.putExtra("HOLENUMBER", holeNumber);
startActivity(intent);
}
});
HERES HOW ACTIVITYCOURSES RESIVE THE DATA
public void addItem() {
if (getIntent().getStringExtra("COURSENAME") != null) {
mCourselist.add(new CoursesItem(getIntent().getStringExtra("COURSENAME"), "Holes:", getIntent().getStringExtra("HOLENUMBER"), R.drawable.ic_delete));
}
}
I'm not sure if this code helped or not... Am I somehow be able to send the whole arraylist from ActivityNewCourse, when save button been clicked? I don't know, I'm kinda dead end and I have no clue what to do, so any suggestions on what to do in this situation would help...