[英]How to filter RecyclerView with ArrayList by spinner item position, Android, java?
[英]Java: Getting arraylist into RecyclerView item
我有RecyclerView(mCourseList),該列表包含項目,並且這些項目包含有關不同課程的一些信息(課程名稱,面值之和等原始數據)。 我需要將每門課程(每個項目)的所有單獨的面值設置為arraylist(mParNumbersIndividually),並將該arraylist包括到recyclerview項目中。
這是我將新商品放入該列表的方式:
/** 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));
現在,我需要將該數組列表(分別為mParNumbersIndividually)添加/添加到我剛剛創建的mCourseList項中。 我怎樣才能做到這一點?
在CoursesItem類中添加具有數組類型的新變量
ArrayList<NewCourseItem> mParNumbersIndividually;
在CoursesItem構造函數中包含一個額外的參數,期望該類型為數組。
CoursesItem(var arg1, var arg2, ..., ..., ArrayList<NewCourseItem> mParNumbersIndividually)
像構造函數中的所有其他變量一樣初始化數組
this.arg1 = arg1;
this.mParNumbersIndividually = mParNumbersIndividually;
//...other variables initialized
為仍在CoursesItem對象內的數組創建getter方法
public ArrayList<NewCourseItem> getParNumbersIndividually(){
return mParNumbersIndividually;
}
然后,將mParNumbersIndividually數組作為CourseItem構造函數的新參數傳遞。
//Pass the array to CourseItem
mCourseList.add(new CoursesItem(arg1, arg2, ..., ..., mParNumbersIndividually));
然后隨時訪問數組,就像CoursesItem對象中的所有其他變量一樣
ArrayList<NewCourseItem> mParNumbersIndividuallyNew = cousersItems.get(i).getParNumbersIndividually();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.