我有一个MVP设置,其中演示者使用以下方法分别填充两个RecyclerView:
@Override
public void populateFollowsRV(List<FollowsRVModel> userDataList) {
followsList.addAll(userDataList);
followsAdapter.notifyDataSetChanged();
}
@Override
public void populateFollowedByRV(List<FollowsRVModel> userDataList) {
followedByList.addAll(userDataList);
followedByAdapter.notifyDataSetChanged();
}
我有一个单独的第三个方法,我想检索followList和followedByList的列表内容,我试图在Fragment类中声明一个名为listOne的全局变量,然后在populateFollowsRV时存储followList / userDataList的内容(调用是为了让内容可以通过类中的其他方法访问,但这似乎不起作用:
//Declare listOne inside the Fragment class
private List<FollowsRVModel> listOne = new ArrayList<>();
@Override
public void populateFollowsRV(List<FollowsRVModel> userDataList) {
followsList.addAll(userDataList);
followsAdapter.notifyDataSetChanged();
//Assign the contents of userDataList to listOne when the presenter calls populateFollowsRV()
listOne = userDataList;
}
listOne在此之后仍然显示为空。
第三种方法
public void populateNonFollowersRV() {
//To test wether listOne has any content
String.valueOf(listOne.size()));
}