[英]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). 我有RecyclerView(mCourseList),该列表包含项目,并且这些项目包含有关不同课程的一些信息(课程名称,面值之和等原始数据)。 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. 我需要将每门课程(每个项目)的所有单独的面值设置为arraylist(mParNumbersIndividually),并将该arraylist包括到recyclerview项目中。
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. 现在,我需要将该数组列表(分别为mParNumbersIndividually)添加/添加到我刚刚创建的mCourseList项中。 How can I do that? 我怎样才能做到这一点?
Add a new variable inside the class CoursesItem having the type of an array 在CoursesItem类中添加具有数组类型的新变量
ArrayList<NewCourseItem> mParNumbersIndividually;
Include an extra parameter to CoursesItem constructor expecting the type array. 在CoursesItem构造函数中包含一个额外的参数,期望该类型为数组。
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 为仍在CoursesItem对象内的数组创建getter方法
public ArrayList<NewCourseItem> getParNumbersIndividually(){
return mParNumbersIndividually;
}
Afterwards pass mParNumbersIndividually array as the new argument to CourseItem constructor. 然后,将mParNumbersIndividually数组作为CourseItem构造函数的新参数传递。
//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 然后随时访问数组,就像CoursesItem对象中的所有其他变量一样
ArrayList<NewCourseItem> mParNumbersIndividuallyNew = cousersItems.get(i).getParNumbersIndividually();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.