简体   繁体   中英

Java: Getting arraylist into RecyclerView item

I have RecyclerView (mCourseList), that list has items and those items contain some information about different courses (course name, sum of par numbers etc primitive data). I need to get every courses (every items) their all individual set of par numbers into arraylist (mParNumbersIndividually) and include that arraylist into the recyclerview item.

This is how I make new item into that list:

    /** Receive primitive data from and make new item with that information **/
    mCourseList.add(new CoursesItem(getIntent().getStringExtra("COURSENAME"), "Holes:", getIntent().getStringExtra("HOLENUMBER"), "Par:", Integer.toString(parCount), R.drawable.ic_delete));

Now I need to add / include that arraylist (mParNumbersIndividually) into that mCourseList item, that I just created. How can I do that?

Add a new variable inside the class CoursesItem having the type of an array

  ArrayList<NewCourseItem> mParNumbersIndividually;

Include an extra parameter to CoursesItem constructor expecting the type array.

 CoursesItem(var arg1, var arg2, ..., ..., ArrayList<NewCourseItem> mParNumbersIndividually)

Initialize the array like every other variables in the constructor

 this.arg1 = arg1;
 this.mParNumbersIndividually = mParNumbersIndividually;
 //...other variables initialized

Create getter method for the array still inside CoursesItem object

  public ArrayList<NewCourseItem> getParNumbersIndividually(){
   return mParNumbersIndividually;
  }

Afterwards pass mParNumbersIndividually array as the new argument to CourseItem constructor.

 //Pass the array to CourseItem
 mCourseList.add(new CoursesItem(arg1, arg2, ..., ..., mParNumbersIndividually));

Then access the array anytime just like all other variables inside CoursesItem object

 ArrayList<NewCourseItem>  mParNumbersIndividuallyNew = cousersItems.get(i).getParNumbersIndividually();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM