重新打开BottomSheetLayout时保持显示Recyclerview项

时间:2018-11-01 15:29:25

标签: android android-recyclerview android-asynctask android-adapter

我有layout,因为BottomSheetLayout包含RecyclerView,在我的代码中,我显示了一些图像,这些图像是从API获取的,这是在RecyclerView中设置适配器的方法。 / p>

 private void setAdapterForRecyclerView(final List<Wallpaper> wlls) {
        arrayList = wlls;
        if (myAdapter == null) {
            myAdapter = new MyAdapter(wlls, FullScreen.this, new RecyclerViewClickListener() {
                @Override
                public void onClick(View view, Wallpaper wallpaper) {

                }

                @Override
                public void onClick(View view, Category categories) {

                }
            });
            recyclerView.setAdapter(myAdapter);
        } else {
            // int position = myAdapter.getItemCount();
            myAdapter.getItems().addAll(wlls);
            myAdapter.notifyDataSetChanged();
        }
        progressbar.setVisibility(View.GONE);
    }

我有一个AsyncTask类,我在其中获取数据并将其存储在ArrayList

@Override
        protected void onPostExecute(List<Wallpaper> wallpapers) {
            super.onPostExecute(wallpapers);
            setAdapterForRecyclerView(wallpapers);
        }

我的问题

当我显示BottomSheetLayout时,一切正常,我看到Recyclerview中的所有图像,但是当我使用 关闭/关闭时(返回按钮或向下滑动) 并再次显示BottomSheetLayoutRecyclerview的所有项目均未显示,要再次显示,我应该完成活动并再次打开它。

我尝试过的方法:

bottomSheet.addOnSheetDismissedListener(new OnSheetDismissedListener() {
            @Override
            public void onDismissed(BottomSheetLayout bottomSheetLayout) {
                arrayList = myAdapter.getItems();
                isCancaled = true;
            }
        });



if (isCancaled) {
            setAdapterForRecyclerView(arrayList);
        } else {
            _fetchDataSimilar.execute();
        }

但仍然无法正常工作,请有人可以帮助我

0 个答案:

没有答案