【发布时间】:2018-11-19 18:46:19
【问题描述】:
我有两个RecyclerView 和一个ArrayList 称为collections,我正在尝试改组这个ArrayList 并获得12 项。
@Override
protected void onPostExecute(List<CollectionsModel> collections) {
super.onPostExecute(collections);
if (isAdded() && getActivity() != null) {
setAdapterForRecyclerView(collections);
setAdapterForRecyclerViewBestCollections(shuffleCollection(collections));
}
}
洗牌方法:
public List<CollectionsModel> shuffleCollection(List<CollectionsModel> collectionsModelList) {
java.util.Collections.shuffle(collectionsModelList);
return collectionsModelList;
}
RecyclerView 1 的适配器方法:
private void setAdapterForRecyclerViewBestCollections(List<CollectionsModel> collectionHelper) {
for (int i = 0; i < 12; i++) {
arrayListCollections.add(collectionHelper.get(i));
}
/*rest of code*/
}
RecyclerView 2 的适配器方法:
private void setAdapterForRecyclerView(final List<CollectionsModel> wlls) {
if (myAdapter == null) {
myAdapter = new MyAdapterCollection(wlls, getActivity(), new RecyclerViewClickListener() {
@Override
public void onClick(View view, Wallpaper wallpaper) {
}
@Override
public void onClick(View view, CollectionsModel collectionsModel) {
}
}, R.layout.collection_item);
recyclerView.setAdapter(myAdapter);
} else {
int position = myAdapter.getItemCount();
myAdapter.getItems().addAll(wlls);
myAdapter.notifyItemRangeInserted(position, position);
}
}
我的问题:
当我运行应用程序时,我看到 RecyclerView 1 和 RecyclerView 2 都是随机的(顺序相同)。
我想要什么:
我想查看RecyclerView 1 中的随机物品顺序和RecyclerView 2 中的正常顺序
【问题讨论】:
标签: java android collections android-recyclerview shuffle